List

“””
use python while loop to print the following output

*****
****
***
**
*

“””

x = 5
while x != 0:
txt = “”
y = 1
while y <= x:
txt += “*”
y = y + 1

print(txt)

x = x – 1

…………………………………………………………………………………

“””
write a program to print even numbers between 20 and 50
“””

x = 20
while x <= 50:
if x % 2 == 0:
print(x)

x = x + 1

………………………………………………………………………………..

“””
write a program to print odd numbers between 50 and 100
“””

x = 50
while x <= 100:
if x % 2 != 0:
print(x)

x = x + 1

……………………………………………..

“””
write a program to print student grade (fail, pass, good, v.good, excellent) based on his degree (int number)
“””

degree = 67

if degree < 50:
print(“fail”)
elif degree >=50 and degree < 65:
print(“pass”)
elif degree >= 65 and degree < 75:
print(“good”)
elif degree >= 75 and degree < 85:
print(“very good”)
elif degree >= 85:
print(“excellent”)

……………………………………………………….

“””
write a program to ask the use to input the radius of the circle then
calculate the area of the circle and print it
area = pi * r^2
“””

from math import pi

# radius of the circle (any value)
r = float( input(“Please enter the radius: “) )

area = pi * r**2

print(“area is ” + str(area))

………………………………………………..

“””
write a program to reverse a string using python loops
“””

txt = “hello, world”
rev_txt = “”

# get length of text
i = len(txt) – 1

while i >= 0:
rev_txt += txt[i]

i = i – 1

print(rev_txt)

……………………………………………

“””
write a program to create a list of numbers
and fill with numbers between 1 – 10
then increase all numbers in the list by 5 using while loop
then print the updated list
“””

nums = []

# fill with numbers between 1 – 10
i = 1
while i <= 10:
nums.append(i)
i += 1

# add 5 to each number
nums_updated = []
for x in nums:
new_val = x + 5
nums_updated.append(new_val)

# print
print(nums_updated)

………………………………………..

“””
write a program to ask the user to fill list with item prices
then print the total price

the ask the user about the discount (ex. 30% for all prices not on total price)
then apply the discount and print the final prices and the final total price
“””

item_count = int( input(“How many items: “) )

prices = []

i = 0
while i < item_count:
item_price = float( input(“enter price of item #” + str(i + 1) + “: “))
prices.append(item_price)

i += 1

print(prices)
total_price = sum(prices)
print( “totalt price = ” + str(total_price) )

discount = float( input(“enter discount : “) )

prices_updated = []
i = 0
while i < item_count:
new_price = prices[i] – prices[i] * discount / 100
prices_updated.append(new_price)

i += 1

print(“updated prices:”)
print(prices_updated)

total_price_updated = sum(prices_updated)
print(“the new total price is ” + str(total_price_updated))

……………………………………………………………………….

“””
use python loop to calculate the sum of the following list
[456, 85, 36, 978, 22, 22.6, 13.8, 20]
“””

my_list = [456, 85, 36, 35, 22, 22.6, 13.88, 20]
sum = 0

i = 0
while i < len(my_list):
sum += my_list[i]

i += 1

print(“sum is ” + str(sum))

…………………………………………………………

“””
write a python program to find the max number on the following list:
[456, 85, 36, 978, 22, 22.6, 13.8, 20]
“””

my_list = [456, 85, 36, 978, 22, 22.6, 13.8, 20]

# set max as the first item in the list
max_num = my_list[0]

i = 0
while i < len(my_list):
if my_list[i] > max_num:
max_num = my_list[i]

i += 1

print(“max number is ” + str(max_num))

…………………………………………………………..

One Response to “Python examples”

  1. KelAutock

    Order Cheap Propecia zoloft require prescription in canada Cialis Tratamiento Impotencia Comprare Cialis Originale

Leave a Reply

Your email address will not be published. Required fields are marked *

  Posts

1 2 3 4
March 25th, 2020

تقرير تسجيل فيديو

     المطلوب تسجيل فيديو لا تزيد مدته عن 5 دقايق عن كيفية العرض والالقاء الجيد ورفعة علي اليوتيوب ووضع […]

March 25th, 2020

مهارات اتصال وعرض فديو الفصل الخامس

https://www.youtube.com/watch?v=RvAaeSEaxH0&feature=youtu.be
March 25th, 2020

محاضرات الفصل الثالث والرابع فديو الجزء الثاني

https://www.youtube.com/watch?v=C4UOFvPGJjE&feature=youtu.be
March 25th, 2020

محاضرات الفصل الثالث والرابع فديو الجزء الاول

https://www.youtube.com/watch?v=4UmJeYcKfn4&feature=youtu.be
March 25th, 2020

Information Security introduction

https://www.youtube.com/watch?v=1Z7UXEgJ6ts&feature=youtu.be
March 25th, 2020

حل امتحان Midterm

March 20th, 2020

Inverse z Transform part3

https://www.youtube.com/watch?v=QwchLQXSulA
March 20th, 2020

Inverse Z Transform part 2

https://www.youtube.com/watch?v=uAxI9xUnrFQ&feature=youtu.be
March 18th, 2020

Algorithms, Flowcharts & Program Design

https://www.youtube.com/watch?v=Wq2IfM1e1eM&feature=youtu.be
March 18th, 2020

Introduction to Computer Network

https://www.youtube.com/watch?v=DBDmYx1dmIM&feature=youtu.be
March 17th, 2020

اسئلة مهارات الاتصال للأعوام السابقة بالاجابات

اسئلة مهارات الاتصال للأعوام السابقة بالاجابات https://drive.google.com/open?id=16xk6b8b0iPQuFuzItK0y-YUYg3qwJ4Gl

March 17th, 2020

تحميل محاضرات الاتصال والعرض

تحميل محاضرات الاتصال والعرض https://drive.google.com/open?id=1Z5L2yAHCp-Rgo6F6sF0Hpd14Ozjq7y-A

March 17th, 2020

تحميل كتاب مهارات الاتصال والعرض

تحميل كتاب مهارات الاتصال والعرض https://drive.google.com/open?id=1Du5Bd_kImzBs6e6bTMAJ3AlIyxdVQBTb

March 17th, 2020

امتحان مهارات اتصال وعرض

Click here
March 4th, 2020

الشيت الاول_ مهارات الاتصال والعرض

أجب علي الاسئلة التالية في كومنت واكتب اسمك كامل بالعربي في اخر الاجابة السؤال الاول : عرف عملية الاتصال ؟ […]

February 12th, 2020

اكتب اسمك

الي طلاب مهارات الاتصال والعرض … اكتب اسمك عربي بالكامل

November 24th, 2019

Why information security is important?

1-What is information? 2-What is information security? 3-Why information security is important? 4-What is information security management?

November 24th, 2019

محاضرات حاسب _ الفصل الخامس

                                                Introduction to Computer Security تحميل المحاضرات عن طريق هذا اللينك https://drive.google.com/open?id=1Yp5IJTlkeltBoVqPLPB8f9jy71HMocBw   مع التحيات بالتوفيق … د. مروة عيد […]

November 11th, 2019

Programming Syllabus

Introduction to programming Computer history Program How do computer execute program? Generations of  programming  language 1st Gen. (Assemble) 2nd  (C  […]

November 11th, 2019

Report (Write an algorithm )

■Write an algorithm Only  that will calculate the roots of a quadratic equation ax^2+bx+c=0 ■ Hint: d = sqrt (    b^2-4ac  […]

October 28th, 2019

محاضرات حاسب 5&6

محاضرات مهارات الحاسب 1& 2 تحميل المحاضرات عن طريق هذا اللينك https://drive.google.com/open?id=1H_ie4ogVyvXaOKSuu4K735Sp5Fv9qKUw   مع التحيات بالتوفيق … د. مروة عيد […]

October 19th, 2019

محاضرات مهارات الحاسب 3& 4

تحميل المحاضرات عن طريق هذا اللينك https://drive.google.com/open?id=1xi2RiMvmYr6g1TXkl5lbCC4gShznb4cY مع التحيات بالتوفيق … د. مروة عيد & د. السيد القناوي

September 30th, 2019

محاضرات مهارات الحاسب 1& 2

محاضرات مهارات الحاسب 1& 2 تحميل المحاضرات عن طريق هذا اللينك https://drive.google.com/open?id=1WyL00v9l6J7_3rZhxRtWT3rNeUfe7Z7v مع التحيات بالتوفيق … د. مروة عيد & […]

July 25th, 2019

تبدأ برمجة ازاي .. ؟

طلاب كتير بتسأل تبدأ برمجة ازاي .. ؟ خد عندك يا هندسة الترتيب المنطقى للتعلم هو كالآتي: HTML (1 month) […]