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 4
April 5th, 2022

Artificial Intelligence: A Modern Approach Lec(6)

Problem-Solving Agents https://drive.google.com/drive/folders/1dATIjI_UbdvoGwvGsVdIEHaa1wEODht3?usp=sharing

April 5th, 2022

Artificial Intelligence: A Modern Approach Lec(5)

Problem-Solving Agents https://drive.google.com/drive/folders/1K5QedjOtuhB03VRcmgETzY50lkZRA05R?usp=sharing

March 19th, 2022

Artificial Intelligence: A Modern Approach Lec(4)

Problem-Solving Agents Download from this link https://drive.google.com/drive/folders/1nmKUlWTd_f3la-BOHXpomWlOe3iLjmni?usp=sharing

March 13th, 2022

Artificial Intelligence: A Modern Approach Lec(3)

INTELLIGENT AGENTS Download from this link https://drive.google.com/drive/folders/1bQesWpipvYzw1FWwxTYO7ld7oa1UTr9_?usp=sharing  

March 5th, 2022

Artificial Intelligence: A Modern Approach Lec(2)

INTRODUCTION What Is AI? Download from this link https://drive.google.com/drive/folders/1SYygpoG-t21_4K6h9V_EllIf9nrWOv1_?usp=sharing Important link https://github.com/aimacode/aima-python https://aimacode.github.io/aima-exercises/ Task https://www.programiz.com/python-programming/keyword-list Optional https://i.am.ai/roadmap/#note  

February 23rd, 2022

Artificial Intelligence: A Modern Approach Lec(1)

INTRODUCTION What Is AI? Download from this link https://drive.google.com/drive/u/4/folders/10CUPZsMHo9simp8pc-PREViDzb2DW1bm Important link http://aima.cs.berkeley.edu/ https://github.com/aimacode/aima-python https://drive.google.com/file/d/1RPrTAQmuBj4NPnIGeZ7n9VEdmZSUoLnK/view https://drive.google.com/file/d/1Kc8e3HFPHRxasbNx3Kvt9R4U447p9otl/view https://www.youtube.com/playlist?list=PLUl4u3cNGP63gFHB6xb-kVBiQHYe_4hSi  

November 26th, 2021

Program Quiz

Click here
May 18th, 2021

ما هي مهارات العرض و التقديم ؟

ما هي مهارات العرض و التقديم ؟

May 11th, 2021

_تقرير _ اكتب الاجابة في كومنت

_اكتب اسمك كامل باللغة العربية_  الاجابة في كومنت اذكر صفات القائد ؟ حدد أهم خصائص فريق العمل ؟ ما هو […]

December 11th, 2020

كتاب مهارات الحاسب الالي

https://drive.google.com/file/d/1rfa4QEJJs-O087r_TVW6vhhzYxcMjQDf/view?usp=sharing

August 28th, 2020

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

     

July 1st, 2020

Research Gate

<a href=”https://www.researchgate.net/profile/El_Sayed_El-Kenawy”>El-Sayed M. El-kenawy on ResearchGate</a>

April 21st, 2020

Filter- Design Part2 Last chapter DSP-محاضره معالجه اشارات

https://youtu.be/zdBbof5-VZ4
April 21st, 2020

Filter- Design Part1 Last chapter DSP-محاضره معالجه اشارات

https://youtu.be/zdBbof5-VZ4
April 12th, 2020

circularconv معالجة اشارات

https://www.youtube.com/watch?v=Qgn6O-FPZ0o&feature=youtu.be
April 9th, 2020

Problems on Filter Realization معالجة اشارات

https://www.youtube.com/watch?v=1ZuyZQSeDso&feature=youtu.be
April 9th, 2020

حل شيت 5 مهارات الحاسب

https://drive.google.com/file/d/1-YvUakJnGyTHyBs6aTFv3yW2-3rUKSno/view?usp=sharing

April 3rd, 2020

REALIZATION معالجة اشارات

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

Z properties معالجة اشارات

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

Report Solve the Following Using Z.T

March 28th, 2020

Revision on zمعالجة اشارات

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

معالجة اشارات رقمية حل الشيت _سيكشن 1

https://drive.google.com/file/d/1J-UuLWmQu6EwnPN9FbvTj9-M1ekPVPQa/view?fbclid=IwAR1wCB2rP9oClLyInY-AAdO0FW4FKgisTARugw21X1BhhLZFIAAFKihXg54

March 26th, 2020

Frequency Response معالجة اشارات

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

Inverse z Transform part 4

https://www.youtube.com/watch?v=8TU-7E5DyvU&feature=youtu.be