Python 1.)Write a for loop that prints all the even integers from 80 through 20
ID: 3907811 • Letter: P
Question
Python
1.)Write a for loop that prints all the even integers from 80 through 20 inclusive, separated by spaces. 2.)Write a for loop that prints in ascending order all the positive integers less than 200 that are divisible by both 2 and 3, separated by spaces. 3.)Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents" on a line by itself. So, if the value of price was 4321, your code would print "43 dollars and 21 cents". If the value was 501 it would print "5 dollars and 1 cents". If the value was 99 your code would print "0 dollars and 99 cents".
Explanation / Answer
1) for i in range(80, 19, -2): print(i, end=' ') 2) for i in range(200): if i % 2 == 0 and i % 3 == 0: print(i, end=' ') 3) print('%d dollars and %d cents' % (price // 100, price % 100))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.