Python Forum
New to Coding, help please?!
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to Coding, help please?!
#2
something like this will suffice, I think. If I understood the question.
If you are using python 2.xxx,... user raw_input instead. if using python 3.xxxx "input is fine"

since I am using 2.xx , I used raw_input... since the question asked to store it in variable, I chose to use int within the variable.
in the future, if multiple user input need to be store, you will be using .split() , but you do not need it here.
ALSO, if you are curious about keeping the code functioning prompting the user to enter correct number again, if the user entered out of bound numbers, you can add a loop (just a tip)

here is a functioning code, that does not necessarily answer your question completely, but gives you a general idea of the if and elif.



user_input = (raw_input("Enter your Age"))
age = int(user_input)   # the storing part, but I prefer combining int on the first line
if age == 0:
 print "You are a Baby!" 
elif age == 1 or age == 2:
 print "You are a toddler" 
elif age == 3 or age == 4:
 print "You are Infant"
elif age >= 5 and age <= 12:
 print "You are a Child"
else :
 print "Enter a whole number between 0 and 12"
Reply


Messages In This Thread
New to Coding, help please?! - by zepel - Apr-20-2017, 01:20 AM
RE: New to Coding, help please?! - by sdcaliber - Apr-20-2017, 01:49 AM
RE: New to Coding, help please?! - by zepel - Apr-20-2017, 03:29 AM
RE: New to Coding, help please?! - by sdcaliber - Apr-20-2017, 04:01 AM
RE: New to Coding, help please?! - by sdcaliber - Apr-20-2017, 04:18 AM
RE: New to Coding, help please?! - by zepel - Apr-20-2017, 04:15 AM
RE: New to Coding, help please?! - by volcano63 - Apr-20-2017, 08:33 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020