Post: Python Beginners Code
06-20-2011, 08:22 PM #1
rohun1
Haxor!
(adsbygoogle = window.adsbygoogle || []).push({}); print "1 = Press for addition"
print "2 = Press for subtraction"
print "3 = Press for multiplication"
print "4 = Press for division"
print

selection=input("Select an option: ")

if selection == 1:
a1=input("Enter the first number: ")
a2=input("Enter the second number: ")
ar=a1+a2
print ar

elif selection == 2:
s1=input("Enter the first number: ")
s2=input("Enter the second number: ")
sr=s1-s2
print sr

elif selection == 3:
m1=input("Enter the first number: ")
m2=input("Enter the second number: ")
mr=m1*m2
print mr

elif selection == 4:
d1=input("What is the first number: ")
d2=input("What is the second number: ")
dr=d1/d2
print dr

else:
print "You didnt even choose any option!"






I just want feedback on this code i created,
I know that its very basic - however i just started python and i intended to create a code that was based on; printing, variables, if statements and operators.

Any help would be appreciated Yes
(adsbygoogle = window.adsbygoogle || []).push({});
06-20-2011, 09:04 PM #2
Originally posted by rohun1 View Post
print "1 = Press for addition"
print "2 = Press for subtraction"
print "3 = Press for multiplication"
print "4 = Press for division"
print

selection=input("Select an option: ")

if selection == 1:
a1=input("Enter the first number: ")
a2=input("Enter the second number: ")
ar=a1+a2
print ar

elif selection == 2:
s1=input("Enter the first number: ")
s2=input("Enter the second number: ")
sr=s1-s2
print sr

elif selection == 3:
m1=input("Enter the first number: ")
m2=input("Enter the second number: ")
mr=m1*m2
print mr

elif selection == 4:
d1=input("What is the first number: ")
d2=input("What is the second number: ")
dr=d1/d2
print dr

else:
print "You didnt even choose any option!"






I just want feedback on this code i created,
I know that its very basic - however i just started python and i intended to create a code that was based on; printing, variables, if statements and operators.

Any help would be appreciated Yes


I think you know, and I think you put them in, but you need to tab in python for the syntax, NGU auto removes tabs, just letting you know, you've probably ran it tabbed anyway, also input only works with numbers, raw_input allows characters (or mistakes) without outputting horrible error messages Smile
06-20-2011, 09:17 PM #3
rohun1
Haxor!
Originally posted by Relevant View Post
I think you know, and I think you put them in, but you need to tab in python for the syntax, NGU auto removes tabs, just letting you know, you've probably ran it tabbed anyway, also input only works with numbers, raw_input allows characters (or mistakes) without outputting horrible error messages Smile


Thanks for the infomation. I now know when to use the appropiate commands when needed.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo