.
1قم بعمل برنامج يتفاعل مع المستخدم بالطريقة التالية:
،يمكنك إتباع الخطوات التالية إذا لم تتمكن من الوصول للحل
.والمحاولة مرة أخرى
# get the input
# divide the number by the number to divide by
# check if the result is divisible by the number to divide by
# get the input
num = float(input('Enter a number: '))
div_by = float(input('Enter The number to divide by: '))
print('-'*20)
# divide the number by the number to divide by
div_result = num/div_by
print(f'The division result is {div_result:.3f}')
# check if the result is divisible by the number to divide by
if num%div_by==0:
print(f'{num} is divisible by {div_by}')
else:
print(f'{num} is not divisible by {div_by}')
.2قم بعمل برنامج يتفاعل مع المستخدم بالطريقة التالية:
،يمكنك إتباع الخطوات التالية إذا لم تتمكن من الوصول للحل
.والمحاولة مرة أخرى
# greeting and getting input
# compare the numbers
# check if the first number is the biggest
# check if the second number is the biggest
# check if the third number is the biggest
# greeting and getting input
print('Please, Enter the Numbers you want to compare\n-----------')
first_num = float(input('Enter The First Number: '))
second_num = float(input('Enter The Second Number: '))
third_num = float(input('Enter The Third Number: '))
print('-----------')
# compare the numbers
if first_num>second_num:
if first_num>third_num:
print(f'{first_num} is the greatest number')
else:
print(f'{third_num} is the greatest number')
else:
if third_num>second_num:
print(f'{third_num} is the greatest number')
else:
print(f'{second_num} is the greatest number')
.3عفوا رصيدك الحالي ال يسمح بتنفيذ العملية.
هي جملة تتكرر كثيرا أمامنا ،وجزء ال غنى عنه في العديد من البرامج،
واآلن حان الوقت لنقوم بإضافتها إلى برامجنا الخاصة.
فلذلك حان الوقت لعمل برنامج يفحص رصيدك الحالي ثم إذا كان كافي
للقيام بعملية الشراء يفعلها ،بحيث يتفاعل مع المستخدم بالطريقة التالية:
،يمكنك إتباع الخطوات التالية إذا لم تتمكن من الوصول للحل
.والمحاولة مرة أخرى
# getting the total amount of money
# getting the price of the items
# calculate the total price
# getting the difference between paid and total price
# check if the amount of money is enough
# getting the total amount of money
amount_money= float(input('Enter The amount of money you have: '))
print('-'*20)
# getting the price of the items
first_price = float(input('Enter The price of The first item: '))
second_price = float(input('Enter The price of The second item: '))
third_price = float(input('Enter The price of The third item: '))
print('-'*20)
# calculate the total price
total_price = first_price + second_price + third_price
# getting the difference between paid and total price
diff_money = amount_money - total_price
# check if the amount of money is enough
if amount_money>=total_price:
print('Items have been purchased successfully')
print(f'The remaining amount is {diff_money:.2f}$')
else:
print('Sorry, You don\'t have enough balance')
# multiply the difference by -1 to remove the negative sign
print(f'You need to add extra {-diff_money:.2f}$')