Professional Documents
Culture Documents
Use of Variable Exercices
Use of Variable Exercices
Solution:
2- Write a program that prompts the user to enter two integers and display
their sum on the screen.
أكتب خوارزمية و مخطط انسيابي ثم برنامج بلغة بايثون يطلب من المستخدم ادخال عددين ثم إيجاد
.محموعهما وطباعة الناتج
Solution:
num1 = int(input("Enter first integer: "))
num2 = int(input("Enter second integer: "))
total = num1 + num2
print("The sum of", num1, "and", num2, "is", total)
4- Write a program which accept principle, rate and time from user and
print the simple interest. The formula to calculate simple interest
is: simple interest = principle x time x rate / 100
, أكتب خوارزمية و مخطط انسيابي ثم برنامج بلغة بايثون يطلب من المستخدم ادخال مبلغ سلفة من بنك
: ثم يقوم بإيجاد قيمة الفائدة حسب القانون التالي,حسب نسبة فائض ولمدة زمنية محددة
100 /الفائدة البسيطة= مبلغ السلفة * المدة بالشهر* نسبة الزيادة
Solution:
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest: "))
time = float(input("Enter the time in years: "))
simple_interest = (principal * time * rate) / 100
print("The simple interest is:", simple_interest)
5- Write a program that accepts seconds from keyboard as integer. Your
program should converts seconds in hours, minutes and seconds. Your
output should like this :
أكتب خوارزمية و مخطط انسيابي ثم برنامج بلغة بايثون يطلب من المستخدم ادخال مدة زمنية بالثواني ثم
يقوم بتحويلها الى ساعات دقائق وثواني يطبع النتائج
Enter seconds: 13400
Hours: 3
Minutes: 43
Seconds: 20
Solution:
seconds = int(input("Enter seconds: "))
hours = seconds // 3600
seconds = seconds % 3600
minutes = seconds // 60
seconds = seconds % 60
print("Hours:", hours)
print("Minutes:", minutes)
print("Seconds:", seconds)
6- Write a program that prompts the user to enter number in two variables
and swap the contents of the variables.
أكتب خوارزمية و مخطط انسيابي ثم برنامج بلغة بايثون يطلب من المستخدم ادخال عددين مختلفين و يقوم
.بتبديل قيمها ثم طباعها
Solution:
# prompt user to enter two numbers
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
7- Write a program that prompts the user to input the radius of a circle and
outputs the area and circumference of the circle. The formula is
أكتب خوارزمية و مخطط انسيابي ثم برنامج بلغة بايثون يطلب من المستخدم ادخال قيمة نصف القطر
وحساب المحيط و المساحة ثم طباعة النتائج
Area = pi x radius2
Circumference = 2 x pi x radius
Solution:
radius = float(input("Enter the radius of the circle: "))
pi=3.14
area = pi * radius ** 2
circumference = 2 * pi * radius
print("The area of the circle is:", area)
print("The circumference of the circle is:", circumference)
Note:
Same exercice can be done for any shape calculations like: rectangle, triangle