This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I'm taking a Coursera course on Python and while working on the first assignment I hit a snag. Can someone please point to what is wrong with my code? the directions for the problem are as follows: Write a function 'problem1_5(age)'. This function should use if-elif-else statement to print out "Have a glass of milk." for anyone under 7; "Have a coke." for anyone under 21, and "Have a martini." for anyone 21 or older.
Tip: Be careful about the ages 7 (a seven year old is not under 7) and 21. Here is my run at writing the program: def problem1_5(age): user_age = input("Please enter your age " "") age = int(user_age) if age<7: print("Have a glass of milk") elif 7<age<21: print("Have a coke") else: print("Have a martini") The program seems to work fine for all ages except for 7-where it prints "Have a martini" instead of a coke... Also when running the program I cannot leave "age" inside the parentheses, I get an error. Instead I have to put a number, right here- problem1_5(age)-before running it. is there a way around this? Thank you guys so much in advance for any assistance.
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...