Exercises to Practice (Module 9)
Take a look at the following section of a Python program:
Α. How many times will the print command be executed?
B. How many times will the command x = x-10 will be executed;
Convert the following program portion into an equivalent using the for instruction.
Write a program that will display the numbers 1, 2, 3, 4 to 1000 using the repetition structure while
Write a program that will read from the keyboard 10 integers, calculate their product, and display it.
Write a program that reads 10 numbers from keyboard and displays the count of positive, negative, and zero elements entered.
Write a program that accepts a positive integer and inverts its digits. (Example: 456 becomes 654)
Write a program that accepts an integer as an input and returns the sum of its digits (ex. Input 56, returns 5 + 6 = 11)
Write a program that accepts an unknown number of integers until their total exceeds 500.
In the end, display the count of numbers that has been accepted.
Write a program that will read random numbers from the keyboard until it gets the number 0. The program will calculate and print:
Α) How many numbers were accepted (do not count 0),
Β) The count of even numbers
Γ) Sum and average of odd numbers.
Write a program that calculates and prints the average of the odd four-digit positive integers.
On a ferry, there are First Class tickets (code A) for 50 $ each and B Class tickets (code B) for $ 20 each. The maximum number allowed passengers are 400. Please assume that the tickets are sold out for this trip. Write a program in Python, which:
1) Accepts the ticket category (code A or B) for each passenger.
2) Display the number of passengers in the first class.
3) Display the ship's total revenue.