def check_num_in_range(range_start, range_end, num):
if num >= range_start and num <= range_end:
return f'{num} in range {range_start} and {range_end}'
else:
return f'{num} NOT in range {range_start} and {range_end}'
num = int(input('Enter a number: '))
check_num_in_range(1, 100, num)
'211 NOT in range 1 and 100'
def round_by_half(num):
rounded_num = int(num/2)
return f'Your number {num} rounded to {rounded_num}'
num = int(input('Enter no of cards being held: '))
round_by_half(num)
'Your number 14 rounded to 7'
import random
def gen_random_num_and_A(num):
random_num = random.randint(num, num+10)
random_num_As = random_num * 'A'
print(f'generated random number: {random_num}, {random_num_As}')
num = int(input('Enter number: '))
gen_random_num_and_A(num)
generated random number: 14, AAAAAAAAAAAAAA
import sys
def check_time_range(time): #, start_time):
# if start_time:
if time > 23 or time < 0:
print('Start time should be in the range of 0-23 hours!')
sys.exit(-1)
start_time = int(input('Enter start hour in 24 hour format: '))
check_time_range(start_time)
end_time = int(input('Enter end hour in 24 hour format: '))
check_time_range(end_time)
price = (end_time - start_time) * 5.50
print(f'Total bill: ${price}')
Total bill: $126.5
import random
doubles_count = 0
for i in range(10000):
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)
if dice1 == dice2:
doubles_count += 1
doubles_percentage = (doubles_count/10000) * 100
doubles_percentage
16.74