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 3 4
November 4th, 2018

Quiz 1

من هو المالك الحقيقي للانترنت ؟ وماهي مراحل تطوير شبكة الانترنت ؟

November 4th, 2018

Lecture 1 what is the internet ?

تاريخ الإنترنت ظهرت فكرة الشبكة الحاسوبية للمرة الأولى خلال المرحلة البدائية من تطوير شبكة الاتصالات، حيث تكمن أهميتها في إتاحة […]

October 28th, 2018

Lecture 5 Computers Have Changed the World

The progress in Computer Science education, digital skills and opportunities that flow computing innovation in machine learning. Here are some […]

October 28th, 2018

Python examples

1- Write Python Program to Print Hello world! https://www.programiz.com/python-programming/examples/hello-world 2- Write Python Program to Add Two Numbers https://www.programiz.com/python-programming/examples/add-number 3- Write Python Program […]

October 24th, 2018

Lecture 3 & 4 ( Understanding Computer Systems)

operating system (OS) manages all of the software and hardware on the computer. Most of the time, there are several different computer programs running at […]

October 24th, 2018

Computer skills quiz 2

Click here
October 18th, 2018

Download Python

 السلام  عليكم ان شاء الله ده اللينك اللي تقدر تحمل من عليه برنامج البايثون بما يناسب نظام التشغيل الخاص بك […]

October 14th, 2018

Report ( python keyword-list )

يرجي تلخيص المحتوي الموجود في هذا اللينك التلخيص يكون بخط اليد https://www.programiz.com/python-programming/keyword-list

October 13th, 2018

Lecture 1& 2 final (Introduction to Computer Technology)

Computer A computer is an electronic device, operating under the control of instructions stored in its own memory that can […]

October 7th, 2018

ظاهرة التوحد

لوحظ مؤخرا أن التوحد  أثار جدل الكثير من العلماء والباحثين لكونه أصبح من أعقد الاضطرابات النمائية إلي الآن . بناءا علي […]

October 7th, 2018

Quiz chapter 1

Click here
October 1st, 2018

العلاقات العامه (Public Relation)

العلاقات العامه (Public Relation) بإختصار تعتبر واجهة أي شركة والممثل لها ؛ كونها لسان و سمعة الشركة في كل ما […]

September 30th, 2018

Lecture 2 Introduction to Computer Technology

Software Software is a generic term for organized collections of computer data and instructions, often broken into two major categories: […]

September 30th, 2018

نظام الساعات المعتمدة

لأى حد هيدرس بنظام الساعات المعتمدة Credit hours وال مش فاهمين النظام ولا ايه ال GPA وعاوز يفهم ايه النظام […]

September 28th, 2018

Quiz 1

What basic tools do you need to start programming? What command would you use for the following in bash (CLI)? […]

September 28th, 2018

Lecture 1 Introduction to Programming

Introduction to Programming If you work in a software development company as a non-programmer, you may wonder what the programmers […]

September 27th, 2018

  (interview مقابله عمل )  اجتماع بين شخص او اكثر يمثل المؤسسة او الشركة اللي عندها استعداد تعين حد ان […]

September 25th, 2018

How Computer and Information System Change our Life?

How Computer and Information System Change our Life?   write your answer in comment including your name (Arabic) (اكتب إجابتك […]

September 24th, 2018

Embedded systemالأنظمة المدمجة

(Embedded systemالأنظمة المدمجة) عبارة عن كمبيوتر صغير معمول عشان ينفذ تاسك واحده او مجموعة تاسكات الفرق ما بين embedded system […]

September 24th, 2018

هل هناك فرق بين الهندسه الكهربيه والهندسه الالكترونيه ؟

اولًا للاجابه عن السؤال هنعرف تعريف كلًا منهم .. اما عن الهندسة الكهربائية فهي أحد فروع علم الهندسة، والذي يختص […]

September 19th, 2018

quiz

Welcome to your Computer Skills Quiz 1 Your Name ID Your Mobile Email A computer is an electronic device ? [...]
September 19th, 2018

Lecture 1 Introduction to Computer Technology

Introduction to Computer Technology what is engineering ? course plan !  Functionalities of a Computer Computer Components Input Devices &  Output […]