# 1) Write a function to check whether a number falls in a given range
def the_range(n):
if n in range(2,8):
print(" %s is in the given range"%str(n))
else :
print( " %s is outside the given range."%str(n))
the_range(9)
9 is outside the given range.
# 2) Reducing the number of cards holding by half, rounded down
cards1=int(input("Enter number of cards in your hand :"))
#we need to cut the number into half so
number1 = (2)
result=cards1//number1
print(result,",is the result")
3 ,is the result
# 3) Print 'A' as many times as the generated number
import random
inputnumber1=int(input("Enter a positive number:"))
inputnumbernumber2=inputnumber1+(10)
inputnumber3= random.randint(inputnumber1, inputnumbernumber2)
print("Generated number is :",inputnumber3)
print("A "*inputnumber3)
Generated number is : 14 A A A A A A A A A A A A A A
# 4) Billing program
hrs1= float((input("Enter starting time in 24 hour time :")))
minhrs = 1
maxhrs = 2
if hrs1 < minhrs:
print(float(input("Enter a valid number between 1 - 23 :")))
else :
hrs2= float(input("Enter ending time :"))
if hrs2 < maxhrs:
print(float(input("Enter a valid time between 1 - 23 :")))
else :
total_hours= float(hrs2 - hrs1)
cost_per_hour = 5.50
total_user_bill = float(total_hours * cost_per_hour)
print("your total bill is : $", total_user_bill,)
your total bill is : $ 11.0
count = 0
import random
for n in range(10000):
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
if dice1==dice2:
count +=1
percent=(count/10000)*100
print(f"The persentage of getting doubles is : {percent}%")
The persentage of getting doubles is : 16.77%
# BELOW PROGRMA IS FROM THE FIRST ASSIGNMENT
# this is the first assignment
#Python Program for How to check if a given number is Fibonacci number?
fib_terms = [0, 1] # first two fibonacci terms
user_input= int(input("Enter the number you want to check"))
while fib_terms[-1] <= user_input:
fib_terms.append(fib_terms[-1] + fib_terms[-2])
if user_input in fib_terms:
print(f"Yes. {user_input} is a fibonacci number.")
else:
print(f"No. {user_input} is NOT a fibonacci number.")
No. 75 is NOT a fibonacci number.
5.5
hrs = input("Enter Hours:")
h = float(hrs)
xx = input("Enter the Rate:")
x = float(xx)
if h <= 40:
print( h * x)
elif h > 40:
print(40* x + (h-40)*1.5*x)
2) Some board games require you to reduce the number of cards you are holding by half, rounded down. For instance, if you have 10 cards, you would reduce to 5 and if you had 11 cards you would also reduce to 5. With 12 cards you would reduce to 6. Write a program that asks the user to enter how many cards they have and print out what their hand would reduce to under this rule.👇
def