Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

1- Write a program that asks the user for his name and then welcomes him.

The output should look like this:


:‫أكتب خوارزمية و مخطط انسيابي ثم برنامج بلغة بايثون يطلب من المستخدم ادخال اسمه ثم طباعة كما يلي‬
Enter your name: Haytham
Hello Haytham

Solution:

name = input("Enter your name: ")


print("Hello", name)

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)

3- Write a program that prompts the user to input a Celsius temperature


and outputs the equivalent temperature in Fahrenheit. The formula to
convert the temperature is: F = 9/5 C + 32 where F is the Fahrenheit
temperature and C is the Celsius temperature.
‫أكتب خوارزمية و مخطط انسيابي ثم برنامج بلغة بايثون يطلب من المستخدم ادخال درجة حرارة سيليزية‬
F = 9/5 C + 32 ‫ وتحويلها الى فهرنياتية حسب القانون‬C0
Solution:
celsius = float(input("Enter the temperature in Celsius: "))
fahrenheit = (9/5)*celsius + 32
print("The temperature in Fahrenheit is:", fahrenheit)

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: "))

# print the original values


print("Before swapping, first number is", num1,"and second number is",
num2)
# swap the values
temp = num1
num1 = num2
num2 = temp

# print the swapped values


print("After swapping, first number is", num1,"and second number is",
num2)

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

You might also like