← All coding practice

Coding Practice · Beginner · October 9, 2026 · 4 min read

Python Coding Exercise #18: Daily Wages

Part of the series Python Practice Exercise — part 18

Before you start: Know input(), int() and float() · Know if statements and f-strings

The question

Please write a program which asks for the hourly wage, hours worked, and the day of the week. The program should then print out the daily wages, which equal hourly wage multiplied by hours worked, except on Sundays when the hourly wage is doubled.

Hourly wage: 8.5
Hours worked: 3
Day of the week: Monday
Daily wages: 25.5 euros
Hourly wage: 12.5
Hours worked: 10
Day of the week: Sunday
Daily wages: 250.0 euros

My Solution

hourly_wage = float(input("Hourly wage: "))
hours_worked = int(input("Hours worked: "))
day = input("Day of the week: ")

daily_wages = hourly_wage * hours_worked

if day == "Sunday":
    print(f"Daily wages: {daily_wages * 2} euros")
else:
    print(f"Daily wages: {daily_wages} euros")

How My Solution Works

1. User inputs

  • hourly_wage uses float(), because wages have decimals, like 8.5.
  • hours_worked uses int(), because the examples use whole hours.
  • day stays a string, because it’s a word.

2. First calculate the daily wages

daily_wages = hourly_wage * hours_worked calculates the pay for an ordinary day. For the first example, that’s 8.5 * 3 = 25.5.

3. Double it on Sundays

The if compares the day with "Sunday":

  • If it is Sunday, the program prints the daily wages times 2.
  • Otherwise (else), it prints the daily wages as they are.

Here is how the two examples work out:

DayCalculationPrinted
Monday8.5 * 325.5
Sunday12.5 * 10 = 125.0, then 125.0 * 2250.0

Why 250.0 and not 250

Because hourly_wage is a float, everything calculated from it is a float too, even when the answer is a whole number. That’s why the sample output shows 250.0 rather than 250. (More on floats in Data Types in Python.)

University Solution

hourly_wage = float(input("Hourly wage: "))
hours_worked = int(input("Hours worked: "))
weekday = input("Day of the week: ")

if weekday == "Sunday":
    # The salary is double on Sundays
    hourly_wage *= 2

total_wage = hourly_wage * hours_worked
print(f"Daily wages: {total_wage} euros")

The University Solution follows the wording of the exercise more literally: on Sundays, the hourly wage is doubled. The if changes hourly_wage itself, and then one calculation and one print() serve both cases. Because the print() appears only once, the sentence Daily wages: ... euros isn’t repeated, so there’s no else branch.

The line hourly_wage *= 2 is a shortcut called an augmented assignment. It means “multiply this variable by 2 and store the result back in it”, which is the same as hourly_wage = hourly_wage * 2. There are matching shortcuts for the other operators:

ShortcutSame as
x += 5x = x + 5
x -= 5x = x - 5
x *= 2x = x * 2
x /= 2x = x / 2

Both programs print exactly the same output. Doubling the hourly wage before the multiplication gives the same number as doubling the total afterwards. Which one you prefer is a matter of style: the first keeps the original wage unchanged, and the second avoids repeating the print().

Things to watch out for

Capital letters matter. The comparison day == "Sunday" is case-sensitive, so typing sunday in lowercase is treated as an ordinary day, and the program prints 125.0 euros instead of 250.0 euros. To ignore capital letters, see String Methods in Python.

Floats can show tiny errors. With an hourly wage of 8.1 and 3 hours, the program prints:

Daily wages: 24.299999999999997 euros

That’s floating-point rounding, not a mistake in the program. The exercise doesn’t ask for rounding, but for real money you could use round(daily_wages, 2), as in Exercise #14.

Half hours won’t work. int() only accepts whole numbers, so entering 7.5 hours stops the program with a ValueError. If you wanted to allow part-hours, you would convert the hours with float() too.

Key takeaways

  • Use float() for values with decimals, like wages, and int() for whole numbers.
  • An if / else picks one of two ways to calculate or print a result.
  • You can change a variable before using it, as in hourly_wage *= 2. The shortcut *= means “multiply and store back”.
  • A value calculated from a float is a float, so the result prints as 250.0.
  • String comparison is case-sensitive. "Sunday" is not "sunday".

✦ This is part of my Python Practice Exercise series, where I work through exercises while learning Python and explain each answer in plain language. ✦


Practice Source: This exercise is taken from the Python Programming MOOC 2026 by the University of Helsinki. I’m working through the exercises as part of my Python learning journey and documenting my answers and explanations here.

Tagged: python · conditionals · float · arithmetic · f-strings