#Sample Program 1
def Range(n):
if n in range(1,99):
print("%s is in the range"%str(n))
else :
print("%s is in outside the given range."%str(n))
Range(46)
Range(100)
46 is in the range 100 is in outside the given range.
# Sample Program 2
number = int(input("Enter a number: "))
if number in range(1,25):
print(number, 'is in the range')
else:
print (number, 'is in out of the given range')
Enter a number: 30 30 is in out of the given range
number_of_cards = int(input("Enter the number of cards you hold: "))
print ('after reducing, the # of cards you have now:',number_of_cards//2)
Enter the number of cards you hold: 25 after reducing, the # of cards you have now: 12
from random import randint
num=eval(input('Enter a positive integer: '))
rand_number=randint(num,num+10)
for i in range(rand_number):
print('A',end='')
print()
Enter a positive integer: 15 AAAAAAAAAAAAAAAAAAA
start_hour = eval(input('Enter starting hour (0-23): '))
end_hour = eval(input('Enter ending hour (0-23): '))
if end_hour >= start_hour:
print('Total: ', (end_hour-start_hour)*5.50)
else:
print('Total:', (24-start_hour + end_hour)*5.50)
Enter starting hour (0-23): 14 Enter ending hour (0-23): 23 Total: 49.5
from random import randint
count = 0
for i in range(1000):
r1 = randint(1, 6)
r2 = randint(1, 6)
if r1 == r2:
count += 1
print('Percentage of doubles:', 100*count/1000)
Percentage of doubles: 17.6