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
July 24th, 2019

تلخيص وحل أسئلة مهارات التحليل

المطلوب تلخيص الفصل الاول وحل الاسئلة الخاصة به كما هي في المحاضرة هنا مع كتابة الاسم بالعربي

July 12th, 2019

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

كتاب مهارات البحث والتحليل https://drive.google.com/open?id=1_VcimjIcHc_74Lw0hx96mMlEWzw5gUpi محاضرات مهارات البحث https://drive.google.com/open?id=1WGdflCQr8FCi-id9aTP-tRHF03T-injY

May 3rd, 2019

محاضرات د. ريهام كاملة

ده اللينك كامل للمحاضرات https://drive.google.com/open?id=13xEjlrqikE118vFuG6eNIpH3c9ubhhd4  

April 22nd, 2019

Information Security Exam

Click here
April 15th, 2019

Information Security Revision

محاضرة هامة …. طريقة الأسئلة    https://drive.google.com/open?id=13Qb4cDfx8eVmoTXoLCR8IiFcChuDhpEv

March 31st, 2019

محاضرات

https://drive.google.com/open?id=1ww7t0sVLpMi9CaCvzWWOXlNjxOcFx3TN

March 19th, 2019

virus attacks

What is the most famous virus attacks in the world?

March 16th, 2019

محاضرات

1- 8085 instruction set Arabic https://drive.google.com/open?id=1RDTaBXB6nybHepz-k9z86EjT-G8jXzlr 2-Programming with 8086 https://drive.google.com/open?id=1YGzthEPYpR3DZqzr9BY_HDblmZH-hLQe 3-8086 Assembly Programs https://drive.google.com/open?id=1dX5JdtgYHnRtzoIQNUWPDwonrE5kTAYn  

March 12th, 2019

المحاضرات

1- Introduction to Microprocessor Systems https://drive.google.com/open?id=1AKQYTiDPHDB-WCGTis-_LU_yuSSOGf_b 2-Memory and input and output ports, Interrupts, Direct Memory Access, Cache memory, Register file. https://drive.google.com/open?id=1MxerliIPqQd7bkT0r3gVHN1UGoqrccg0 […]

March 4th, 2019

Microprocessor Notes

Download this file https://drive.google.com/open?id=1g6bEojykzvlaaNgNsNBLZyq2ism1A-Ai

March 4th, 2019

Report

March 4th, 2019

Report

March 4th, 2019

Report

What is operating systems, Types of operating systems, and how it works? What is an Application? its Types? give examples […]

March 4th, 2019

Midterm Exam

 

February 18th, 2019

موقع مهم

الموضعات هنا ممتازة في البداية .. ربنا يوفق الجميع http://www.qariya.info/electronics/beginer_page.htm

February 17th, 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?

February 16th, 2019

How computer change our life ?

How computer change our life ?  Leave your answer in comment 

December 14th, 2018

QUIZ

“”” Write a program do the following: – ask the user to enter number of students in the class – […]

December 10th, 2018

Python Examples Run

Program 1 https://trinket.io/python/f80f228607 Program 2 https://trinket.io/python/22ce0558f5 Program 3 https://trinket.io/python/4188b4c32c Program 4 https://trinket.io/python/2b043e2b05 Program 5 https://trinket.io/python/a53e7f9e82 Program 6 https://trinket.io/python/7f7a015b33 Program 7 […]

December 9th, 2018

اختار موضوع واحد فقط

كيفية إنشاء موقع مجاني والتسويق من خلاله التسويق بإستخدام محركات البحث وكيفية الوصول إلي عملاؤك اسرع من منافسيك . علم […]

December 4th, 2018

Python examples

“”” use python while loop to print the following output ***** **** *** ** * “”” x = 5 while […]

December 3rd, 2018

امتحان مهارات البحث علي الانترنت

Click here
November 19th, 2018

Quiz 3

ما هو محرك البحث ؟ ما هي أهم خدمات جوجل ؟

November 19th, 2018

Quiz 2

مميزات وعيوب البحث الالكتروني ؟