Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

3
Beginner program help
Post Body

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.

Duplicate Posts
2 posts with the exact same title by 1 other authors
View Details
Author
Account Strength
80%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
225
Link Karma
81
Comment Karma
144
Profile updated: 5 days ago
Posts updated: 3 days ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago