+ 2

Calculator in Python

Hello guys, I try to build a calculator which reads values typed in by the user. I have the idea, but not all the knowledge. anyone can help me? this is the code: print('GreatClaculatorMachineEver!') a = ('addition') s = ('subtraction') m = ('multiplication') print('Befor we start my name is Albert Einstein program.' '\nWould you like to use addition(a), subtraction(s) or multiplication(m)?') i = input('Introduce the leters a, s or m: ') if i==a: print('Well don, you chose', a) a_1=(input('Introduce your 1st number')) a_2=(input('Introduce your 2nd number')) a_3=(input('Introduce your 3rd number')) total_a=a_1+a_2+a_3 sub_total_a=total_a/3 print('\nYour sum total is', total_a'.') print('\nYour average sum is', sub_total_a'.') elif i==s: print('Well don, you chose', s) s_1=(input('Introduce your 1st number')) s_2=(input('Introduce your 2nd number')) s_3=(input('Introduce your 3rd number')) total_s=s_1-s_2-s_3 sub_total_s=total_s/3 print('\nYour subtraction total is', total_s'.') print('\nYour average sum is', sub_total_s'.') else i==m: print('Well don, you chose', m) m_1=(input('Introduce your 1st number')) m_2=(input('Introduce your 2nd number')) m_3=(input('Introduce your 3rd number')) total_m=m_1*m_2*m_3 sub_total_m=total_m/3 print('\nYour multiplication total is', total_m'.') print('\nYour average sum is', sub_total_m'.')

9th Feb 2017, 4:44 PM
Efraim Ié
Efraim Ié - avatar
6 Réponses
+ 8
eval()
10th Feb 2017, 1:16 AM
Ahri Fox
Ahri Fox - avatar
+ 3
Dude this calculator is simple and you should learn more about control structure before developing this app. I believe you would be able to implement easily after some practice.
9th Feb 2017, 6:11 PM
Ravindra Sisodia
Ravindra Sisodia - avatar
+ 2
dude. don't let these people discourage you. we all had to start somewhere. yes the code can be significantly improved, and I'm sure you will expand on it and improve on it as you continue on your learning journey. I'd say a very decent first attempt.
18th Feb 2017, 10:27 PM
Stefan Ellis
Stefan Ellis - avatar
+ 2
cheers Stefan Ellis
18th Feb 2017, 10:47 PM
Efraim Ié
Efraim Ié - avatar
+ 2
Problem fixed! print('Claculator Machine!') a = ('addition') s = ('subtraction') m = ('multiplication') print('Hello. My name is Albert.' '\nWould you like to use addition(a), subtraction(s)' '\n or multiplication(m)?') i = input('Introduce the letters a, s or m: ') if (i == 'a'): print('Well done, you chose', a,'.') a_1 = (int(input('Introduce your 1st number: '))) a_2 = (int(input('Introduce your 2nd number: '))) a_3 = (int(input('Introduce your 3rd number: '))) total_a = (a_1 + a_2 + a_3) sub_total_a = total_a / 3 print('Your sum total is', total_a) print('Your average sum is', sub_total_a) print ('Try again if you want to test subtraction' '\nmultiplication.' '\nOtherwise, thank you for your time.' '\nGood bye!') elif (i == 's'): print('Well done, you chose', s,'.') s_1 = (int(input('Introduce your 1st number: '))) s_2 = (int(input('Introduce your 2nd number: '))) s_3 = (int(input('Introduce your 3rd number: '))) total_s = (s_1 - s_2 - s_3) sub_total_s = total_s / 3 print('Your subtraction total is', total_s) print('Your average subtraction is', sub_total_s) else: print('Well done, you chose', m,'.') m_1 = (float(input('Introduce your 1st number: '))) m_2 = (float(input('Introduce your 2nd number: '))) m_3 = (float(input('Introduce your 3rd number: '))) total_m = (m_1 * m_2 * m_3) sub_total_m = total_m / 3 print('Your multiplication total is', total_m) print('Your average multiplication is', sub_total_m)
21st Feb 2017, 4:25 PM
Efraim Ié
Efraim Ié - avatar