IDLE is a tool for interacting with Python and writing Python programs. You will find IDLE convenient for a number of reasons:
Variables, Operators and Assignment Statements
>>>print "first Python lab"
>>># display welcome message
>>>y = x+5
>>>x = 8
>>>z = 3
>>>t = 3.0
for <variable> in <sequence>:
i = 1 for j in [1,2,3,4,5]: i = i * j print i
What does the program compute? Change it, so that the user decides at which number to stop.
To write and test the program, do the following:
1. For loop practice: refer to the for loop example above.
Write a simple Python program that prompts the user for inputs x and y and computes "x to the power of y". Assume that we've lost the ** function so you cannot use it. Also assume that both inputs (x and y) are integers.2. (optional) Write a simple program to solve a practical problem.
Recall the changeAdder example shown in lecture. We will do the reverse in this lab: given an amount in cents that is less than a dollar, determines the method of giving the amount using the fewest coins. The result should be given in the form shown below (pennies first, then nickels, dimes, and quarters, each on a separate line).
Enter the total amount in cents (< 100): 33
Your program should use the input function to get the total amount of change from the user, then perform the necessary computations and output the result as shown above. Your program does not need to handle problematic inputs; it may assume that the number entered by the user is a positive integer less than 100.
You may first use some examples to figure out the algorithm, i.e. if this problem were in your mathematics homework instead of computer science, what would you do? Then you can write pseudocode for the algorithm, and translate it to a Python program.