Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 6.189 A Gentle Introduction to Programming
- # Mechanical MOOC
- # Exercise 1.8
- print '*****LOOPS*****'
- # Task 1
- # prints out decimal equivalents of 1/2, 1/3, 1/4, ..., 1/10
- for i in range(2,11):
- print 1.0/i
- # Task 2
- # Countdown from a given positive number to 0
- n = input('Enter a positive number: ')
- if n > 0:
- while n >= 0:
- print n
- n -= 1
- else:
- print "Invalid input"
- # Task 3
- #Calculating exponentials
- base = input("Enter base: ")
- exp = input("Enter exponent: ")
- x = base # Here I place the initial value for calculation
- # I use FOR LOOP to set the number of times I want to
- # itirate this calculation
- for n in range(1, exp):
- x *= base # This is the formula of calculation
- print x # This shows what's going on in the process
- print x
- # Task 4
- # Making a user enter an integer divisible by 2
- n = input('Enter an even integer number: ')
- # Making sure the input is an even integer
- while n % 2 != 0:
- print "No, it's not even! Even means divisible by 2"
- n = input("Enter an EVEN integer: ")
- while type(n) == float:
- print "I asked to enter integer, didn't I?"
- n = input('Enter an even INTEGER number: ')
- print "Congrats, you've done it!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement