Question: Programming with Python Warning you are allowed to use IF and loop structures, Coins Imagine you have a set of squares and starting from the
Programming with Python
Warning you are allowed to use IF and loop structures,
Coins
Imagine you have a set of squares and starting from the first square to the last, you are supposed to put n times the number of coins in the previous square to the next one. For example, if you start with m coins, you should continue by putting mn, mn^2, mn^3 coins to the following squares. The number of squares and the number of coins put on the first square will be determined by the user. After getting your inputs, you need to calculate how many coins will be on each square and in total.
In this homework you need to do the following:
Ask user the number of squares, the multiplication coefficient (n) and the number of coins to put into the first square (m). All inputs should be positive integers. If you get an invalid input, your program should give a proper error immediately, before taking any other input and getting terminated. Calculate the number of coins on each square and print their sum at the end. = + + ^2 +
Sample screen output:
>> Enter the number of squares: -3 Please enter an integer larger than zero! >> Enter the number of squares: 4 Enter the number of coins on the first square (m): -1 Please enter an integer larger than zero! >> Enter the number of squares: 4 Enter the number of coins on the first square (m): 2 Enter the multiplication coefficient (n): -6 Please enter an integer larger than zero! (
>>
Enter the number of squares: -3
Please enter an integer larger than zero!
>>
Enter the number of squares: 4
Enter the number of coins on the first square (m): -1 Please enter an integer larger than zero!
>>
Enter the number of squares: 4
Enter the number of coins on the first square (m): 2 Enter the multiplication coefficient (n): -6
Please enter an integer larger than zero!
>>
Enter the number of squares: 4
Enter the number of coins on the first square (m): 2 Enter the multiplication coefficient (n): 3
. square: 2 coins. . square: 6 coins. . square: 18 coins. . square: 54 coins. You got 80 coins in total!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
