0% found this document useful (0 votes)
33 views

Program Python Notepad

The document contains Python code examples demonstrating the use of for and while loops to print numbers, names, tables and lists. It includes programs to: 1) Print numbers from -1 to 1 using a for loop 2) Print the squares of numbers from 1 to 10 using a for loop 3) Print numbers and tables using for and while loops 4) Print even numbers from 1 to 10 using a while loop 5) Print lists and find their lengths 6) Calculate total of receipts entered until a negative number

Uploaded by

Junaid pc
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Program Python Notepad

The document contains Python code examples demonstrating the use of for and while loops to print numbers, names, tables and lists. It includes programs to: 1) Print numbers from -1 to 1 using a for loop 2) Print the squares of numbers from 1 to 10 using a for loop 3) Print numbers and tables using for and while loops 4) Print even numbers from 1 to 10 using a while loop 5) Print lists and find their lengths 6) Calculate total of receipts entered until a negative number

Uploaded by

Junaid pc
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#write apython program that print digit from (20) digit from -1 to 1

import math
x=-1
for i in range(20):
print("x",(x))
x=x+.1

#use of for loop in python

import math
for x in range(20):
y=x**2-2*x+8
print(x,y)

##write a python program to print digit 1 to 10 using FOR loop


for i in range(1,11):
print(i)

#print ypur name 10 times using for loop


for i in range(10):
print("junaid")

#write a python program to print digit 1 to 10 using while loop

a=1
while a<=10:
print (a)
a=a+1
#write a python program to print sum of reciept amount until negative number is not
enter after then program should rteturn total of reciept number

a=1
s=0
while a>0:
a=int(input("enter a amount"))
if(a>0):
s=s+a
print(s)

#write a python program to print even digit 1 to 10 using while loop

a=0
while a<=10:
if a%2==0:
print(a)
a=a+1
#write a python program to print digit 5 by using while loop

a=1
i=0
while i<=10:
if a==5:
print(a)
a=a+1

##write a pyhton program to print table of 3

i=3
while i<=30:
print(i)
i=i+3

#write a pyhton program to print table of inputed number

table=int(input("enter a table"))
number=int(input("enter a number"))
limit=int(input("enter a limit"))

while number<=limit:
print(number*table)

number=number+1

#write a pyhton program to print table of 2

a=2
for i in range(1,11):
print(a)
a=a+2

#write a pyhton program to print table of inputed number


a=int(input("enter a number"))
for i in range(1,11):
print(a*i)

#write a pyhton program to print list


fruits=["apple","mango","banana"]
print (fruits[1])
#write a pyhton program to print list length
fruits=["apple","mango","banana"]
print(len(fruits))

#write a pyhton program to print list length and selected index


fruits=["apple","mango","banana"]
a=(len(fruits))
print("length of list is",a)
print ("selected index is",fruits[1])

#write a python to print total reciept amount and number of reciept enter by the
user

a=0
s=0
nr=0
while a>=0:
a=int(input("enter a number"))
nr+=1
if a<=0:
print("total amouny",s)
print("total nuumber oif reciept",nr-1)
s=s+a

You might also like