2️⃣

4.2 Practice

Practice

Hours

Write a program that asks the user how many hours they spend on the internet per day and print if they're addicted or not based on the hours. (5 or more hours is addicted, less than that is not addicted).

💡

For a challenge, see if you can write the same program, except that the user is addicted to the internet if the number of hours that they spend on the internet is greater than 2 times the remainder of hours / 7

Difference

Write a Python program that prompts the user to enter a number. If the number is greater than 17, print "Negative". Otherwise, print the result of 17 minus the given number.

Grade

Write a program that asks the user to enter the score for a student's test. Print the letter grade that the test score receives.

💡

For a challenge, see if you can write the same program, but without using >= anywhere.

Sum Compare

Get 3 numbers from the user. Find the biggest number, then add all the numbers together. If the sum is bigger than 2 times the biggest of the 3 numbers, print the sum. If it's smaller, multiply the sum by 3 and print the product.

Four Numbers

Ask the user for 4 numbers. Use only 3 if/else blocks to find the largest number. You may not use elifs. For example, this counts as one if/else block

if (2 > 3):
	print("yay")
else:
	print("nay")

This question is really tricky and requires some ingenuity

Menu

A restaurant menu has food and drink sections, each from which the customer must choose an order. By default, any combination of food and drink orders are $1,000,000,000.

But, if the customer enters "french toast" AND "coffee", there is a discount of $1. If the customer enters "chicken soup" OR "apple juice", the price increases by $1.

Write a program that takes an order from a user and prints out the appropriate price. Assume that all inputs are in lowercase and that it is always food first, and then drink.

Walk

Timmy wants to walk his pet dog twice a day. He decides that the second walk has to be 6 hours after the first walk ends. Each walk takes exactly 1 hour.

Timmy is forgetful, so he decides to write a program that tells him whether or not it is time to walk his dog a second time.

Write a program that takes the input of the hour and the minute when the first walk started and the current time, and prints "Late" if it is past the scheduled time for the second walk, "Now" if it is exactly the right time, and "Early" if it is before the second walk time.

Assume all inputs and outputs must be in 24-hour style (e.g. 4 PM is 16:00), and that Timmy will schedule his walks so that the second walk will not start later than midnight (24:00)

Square

Write a program that takes an integer input, and prints the square of that number if it is even, and prints the number itself otherwise.

Month and Day

Write a program that takes user input of the month and date, and prints out "Boo!" if it is Halloween, and "April fools!" if it is April fools' day. If it is any other month and date, print "It's not Halloween or April Fools..." Assume all inputs are integers (for example, month 1 is January)

Temperature

Hoppity the Rabbit wrote some code, but it doesn't run correctly and he needs your help! The following program is supposed to print a string based on a numerical input of the temperature. See if you can fix it for him!

Money Check

Write a program that asks for a person's amount of money (as a floating-point). If the person's amount of money is 0, print "Bankrupt". If not, print "Not Bankrupt". If the person's amount of money is greater than 1000.0, then print "Rich".

Previous Section

Next Section

⚖️

Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.