2019-06-13
  • |
  • daafoor
  • |
  • مشاهدات: 16639

امثلة python

while loops

 

برنامج يطبع كلمة hello  مئة مرة

#write python program to print the word 'hello' 100 times
counter=1
while counter<=100:
    print('hello')
    counter=counter+1

 

برنامج بايثون يطبع الاعداد بين 1 الى 100

#write python program to print the numbers between 1 to 100
counter=1 
while counter<=100:
    print(counter)
    counter=counter+1

 

برنامج يطبع قيمة العداد في كل لفة , وبعد انتهاء الحلقة يطبع كلمة good bye

count = 0
while (count < 9 xss=removed>

 

لعبة تحزير الكلمات, لكن باستخدام الحلقات, بحيث يظل البرنامج يطلب من المستخدم ادخال القيمة مادامت غير صحيحة

#guess game
correctNumber=int(input("please enter the number "))
running=True
while running==True:
    guess=int(input("enter your guess:"))
    if guess==correctNumber:
        print("congratulations,, you guessed it!")
        running=False
    elif guess>correctNumber:
        print("wrong number, your number is bigger than correct number")
    elif guess

 

برنامج يطبع الاعداد الزوجية بين 1 الى 100

#write python program to print the even numbers between 1 to 100
c=1
while c<=100:
    if c % 2==0:
       print(c)
    c = c + 1
    
print("done")

 

 برنامج يطبع الاعداد الفردية بين 1 الى 100

#write python program to print the odd numbers between 1 to 50
x=1
while x<=100:
    if x % 3==0:
       print(x)

print("done")

 

برنامج لحساب قيمة الاس

#Write python program that computes n^p where n and p are two numbers given by the user.
n=int(input('enter the number'))
p=int(input('enter the power'))
counter=1
result=1
while counter<=p:
    result*=n #same as result=result*n
    counter+=1 #same counter=counter+1
print("result is :",result)

 

برنامج يحسب مجموع الجذور التربيعية للاعداد من 1 الى n

#Exercise: Write python program that computes the sum of the squares between 1 and n where n is given
#by the user. Use while to ensure that the value of n is strictly positive.

import math
summ=0
n=int(input("enter n:"))
i=1
while i<=n:
 summ+=math.sqrt(i)
 i+=1
print("sum of squares is: ",summ)

 

i=1
while i<=10:
    print('cuckoo!',end='')
    i+=1

 

 

الفيديو التالي يشرح الامثلة السابقة بالتفصيل:

 

 

ابحث عن مسائل برمجة بايثون | Python programming بالانجليزي

هل أعجبك المحتوى؟

محتاج مساعدة؟ تواصل مع مدرس اونلاين الان!

التعليقات
لا يوجد تعليقات
لاضافة سؤال او تعليق على المشاركة يتوجب عليك تسجيل الدخول
تسجيل الدخول