Tagged: python
Everything tagged "python", newest first.
Python Coding Exercise #14: Soup or No Soup
A beginner Python exercise on if/else with strings — ask for a name, skip the order for one particular customer, and work out the total cost for everyone else without floating-point surprises.
Python Coding Exercise #13: Simple if Statements
Two short beginner Python exercises on if statements and comparison operators — print "Orwell" only when the number is 1984, and calculate the absolute value of a number.
Python Coding Exercise #12: Students in Groups
A beginner Python exercise on integer division, the remainder operator and if/else — work out how many groups a class needs when the students don't divide evenly.
Python Coding Exercise #11: Food Expenditure
A beginner Python exercise that combines int(), float(), arithmetic and a multi-line f-string — estimate a user's weekly and daily food expenditure from three inputs.
Python Coding Exercise #10: Fix the Code (Product)
A beginner Python debugging exercise — why a program that asks for three numbers prints 125 instead of 30, and how using separate variables fixes it.
Python Coding Exercise #09: Calculations with Input
Three short beginner Python exercises that read numbers with input() and calculate with them — seconds in a number of days, the sum and product of two numbers, and the sum and mean of four numbers.
Python Coding Exercise #08: Converting Input to Integer
Two beginner Python exercises that turn input() into an integer with int() so it can be used in a calculation — multiplying a number by five, and working out someone's age from their birth year.
Python Coding Exercise #07: Print a Single Line
A beginner Python exercise on the end argument of print() — how to make several print commands write their output on one line instead of one line each.
Python Coding Exercise #06: Arithmetics
A beginner Python exercise on arithmetic operators and f-strings — print the sum, difference, product and quotient of two variables so the program still works when the values change.
Python Coding Exercise #05: Extra Space
A beginner Python exercise on print() and whitespace — why commas in print() add extra spaces, and how f-strings give you exact control over the output.