1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2012
Posts
2
Rep Power
0

#### First Script

This is my first time ever *programing*
I have been studying python for about 3 days now. heres my first program, it's really nothing just a simple calculator, it was more of a test for me then anything. Does simple addition, division, multiplication, and subtraction. Like I said this is my first script, let alone first language, I'm sure there is flaws in this, and probably easier ways to code a calculator, but I tried, all I can say.

Code:
```dash = '*'
print dash * 80
print dash * 70
print dash * 60
print dash * 50
print dash * 40
print dash * 30
print dash * 20
print dash * 10
print("Choose an equation!")
print dash * 20
print(" A - (-), B - (+), C - (/), D - (*)")
equation_picked = raw_input()
#SUBTRACTION
if equation_picked == 'a' or equation_picked == 'A':
if equation_picked == 'a' or equation_picked == 'A':
print("------------------------------Subtraction------------------------------")
first_value = input("Enter the first value : ")
second_value = input("Enter the second value : ")
print ("Your result is : ")
print first_value, '-',  second_value, '=', first_value - second_value
print dash * 30
print dash * 40
print dash * 50
print dash * 60
print dash * 70
print dash * 80
if equation_picked == 'b' or equation_picked == 'B':
if equation_picked == 'b' or equation_picked == 'B':
equation_picked == 'B'
add_value_1 = input("Enter First value : ")
add_value_2 = input("Enter Second value : ")
print ("Your result is : ")
print dash * 70
print dash * 60
print dash * 50
print dash * 40
print dash * 30
print dash * 20
print dash * 10

#DIVISION

if equation_picked == 'c' or equation_picked == 'C':
if equation_picked == 'c' or equation_picked == 'C':
print("------------------------------Division--------------------------------")
sub_value_1 = input("Enter First value : ")
sub_value_2 = input("Enter second value : ")
print sub_value_1, '/', sub_value_2, '=', sub_value_1 / sub_value_2
print dash * 20
print dash * 30
print dash * 40
print dash * 50
print dash * 60
print dash * 70
print dash * 80
if equation_picked == 'd' or equation_picked == 'D':
print("------------------------------Multiplication------------------------------")
mul_value_1 = input("Enter First value : ")
mul_value_2 = input ("Enter Second value : ")
print mul_value_1, '*', mul_value_2, '=', mul_value_1 * mul_value_2
print dash * 90
print dash * 80
print dash * 70
print dash * 60
print dash * 50
print("Just a simple Calculator!")```
2. #### Awesome, it works.

Still, you must want remarks. Reworking your program I've inserted a function to remove your most common statement, shown how a list can be useful, and recommend string functions to simplify your effort.
Code:
```dash = '*'

################################################################
# Use a function for repeated statements
def dash_it_all(lengths):
for L in lengths:
print dash*L

dash_it_all([80, 70, 60, 50])
dash_it_all([40, 30, 20, 10])
print("Choose an equation!")
dash_it_all([20])
print(" A - (-), B - (+), C - (/), D - (*)")
equation_picked = raw_input()

################################################################
# Often you can simplify tests using a common case
equation_picked = equation_picked.lower()

if equation_picked == 'a':
print("------------------------------Subtraction------------------------------")
first_value = input("Enter the first value : ")
second_value = input("Enter the second value : ")
print ("Your result is : ")
print first_value, '-',  second_value, '=', first_value - second_value
dash_it_all([10*i for i in range(3,9)])

if equation_picked == 'b':
add_value_1 = input("Enter First value : ")
add_value_2 = input("Enter Second value : ")
print ("Your result is : ")
dash_it_all([10*i for i in range(7,0,-1)])

if equation_picked == 'c':
print("------------------------------Division--------------------------------")
sub_value_1 = input("Enter First value : ")
sub_value_2 = input("Enter second value : ")
print sub_value_1, '/', sub_value_2, '=', sub_value_1 / sub_value_2
dash_it_all([10*i for i in (2,3,4,5,6,7,8)])

if equation_picked == 'd':
print("------------------------------Multiplication------------------------------")
mul_value_1 = input("Enter First value : ")
mul_value_2 = input ("Enter Second value : ")
print mul_value_1, '*', mul_value_2, '=', mul_value_1 * mul_value_2
dash_it_all([90, 80, 70, 60, 50])

print("Just a simple Calculator!")```
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2012
Posts
2
Rep Power
0
Originally Posted by b49P23TIvg
Still, you must want remarks. Reworking your program I've inserted a function to remove your most common statement, shown how a list can be useful, and recommend string functions to simplify your effort.
Code:
```dash = '*'

################################################################
# Use a function for repeated statements
def dash_it_all(lengths):
for L in lengths:
print dash*L

dash_it_all([80, 70, 60, 50])
dash_it_all([40, 30, 20, 10])
print("Choose an equation!")
dash_it_all([20])
print(" A - (-), B - (+), C - (/), D - (*)")
equation_picked = raw_input()

################################################################
# Often you can simplify tests using a common case
equation_picked = equation_picked.lower()

if equation_picked == 'a':
print("------------------------------Subtraction------------------------------")
first_value = input("Enter the first value : ")
second_value = input("Enter the second value : ")
print ("Your result is : ")
print first_value, '-',  second_value, '=', first_value - second_value
dash_it_all([10*i for i in range(3,9)])

if equation_picked == 'b':
add_value_1 = input("Enter First value : ")
add_value_2 = input("Enter Second value : ")
print ("Your result is : ")
dash_it_all([10*i for i in range(7,0,-1)])

if equation_picked == 'c':
print("------------------------------Division--------------------------------")
sub_value_1 = input("Enter First value : ")
sub_value_2 = input("Enter second value : ")