100% found this document useful (1 vote)
287 views4 pages

Python Programs for Various Tasks

The document contains 12 code snippets covering topics like income tax calculation, palindrome checking, student data storage, password protection, prime number finder, and file copying. Each snippet includes inputs, conditional logic, and outputs to solve problems related to various data types and file handling. Overall the snippets demonstrate basic programming concepts like conditionals, loops, functions, and file I/O.

Uploaded by

ANWESHA DUTT
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
287 views4 pages

Python Programs for Various Tasks

The document contains 12 code snippets covering topics like income tax calculation, palindrome checking, student data storage, password protection, prime number finder, and file copying. Each snippet includes inputs, conditional logic, and outputs to solve problems related to various data types and file handling. Overall the snippets demonstrate basic programming concepts like conditionals, loops, functions, and file I/O.

Uploaded by

ANWESHA DUTT
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

1.

aline's visit
print("Hello "+input("Enter the name:")+"! Welcome to our planet Earth.")
[Link] tax
age=int(input("Enter the age:\n"))
tax=0
if age>18 and age<=100:
income=int(input("Enter the income:\n"))
if income>0:
if age<=60:
if income<=250000:
tax=(income*0)/100
elif income>250000 and income<=500000:
tax=(income*10)/100
elif income>500000 and income<=1000000:
tax=(income*20)/100
elif income>1000000:
tax=(income*30)/100
elif age>60 and age<=80:
if income<=300000:
tax=(income*0)/100
elif income>300000 and income<=500000:
tax=(income*10)/100
elif income>500000 and income<=1000000:
tax=(income*20)/100
elif income>1000000:
tax=(income*30)/100
elif age>80 :
if income<=500000:
tax=(income*0)/100
elif income >500000 and income<=1000000:
tax=(income*20)/100
elif income>1000000:
tax=(income*30)/100
print("The Tax amount is: %.2f" % tax)
else:
print("Invalid Income")
else:
print("Invalid Age")
[Link] report generation
x=int(input("Dead Count:"+"\n"))
if x>=0:
y=int(input("Injured Count:"+"\n"))
if y>=0:
z=int(input("Safe Count:"+"\n"))
if z>=0:
print("TSUNAMI REPORT OF JAPAN"+"\n"+"The number of people"+"\
n"+"Dead:"+str(x)+"\n"+"Injured:"+str(y)+"\n"+
"Safe:"+str(z)+"\n"+"Please help the people who are suffering!!!")
else:
print("Invalid input")
else:
print("Invalid input")
else:
print("Invalid input")
[Link]
word=input("Enter the string:")
new_word=[Link]().replace(" ","")
if new_word[::1]==new_word[::-1]:
print("Yes, the string is a palindrome!")
else:
print("No, the string is not a palindrome!")
[Link] Student Data
n=int(input("Enter the no of student details to be created : "))
data=[]
subdict={}
if n>0:
for i in range(n):
name=input("Name: ")
age=int(input("Age: "))
if age<10 or age>20:
print("Invalid Input")
exit()
location=input("Location: ")
[Link]({'Name':name,'Age':age,'Location':location})
[Link](subdict)
subdict={}
print("Here's the list of student details :")
for i in data:
print(i)
sn=input("Enter the training location: ")
res=[sub['Name'] for sub in data if sub['Location']==sn]
if not res:
print("Invalid location")
else:
print("Student(s) enrolled in this training location:")
for i in res:
print(i)
else:
print("Invalid Input")
[Link] protection
n1=int(input("Enter the total [Link] plots: "))
f=e=o=0
l=[]
if n1<=20 and n1>=1:
print("Enter the numbers of each plot")
for i in range(n1):
i=int(input())
if i<=0:
print("Invalid Input")
exit()
[Link](i)
o=(sum([i for i in l if i%2!=0]))
e=sum([i for i in l if i%2==0])
avg=float((e+o)/2)
print("The password for the file is: %.2f" % avg)
else:
print("Invalid Input")
[Link] or fail
n=int(input("Enter the no. of subjects: "))
l=[]
f=0
p=0
if n>0:
print("Enter the marks:")
for i in range(n):
i=int(input())
if i>=0 and i<=100:
[Link](i)
else:
print("Invalid mark")
exit()
for i in l:
if i<=50:
f=f+1
else:
p=p+1
print("No. of subjects passed:",p)
print("No. of subjects failed:",f)
else:
print("Invalid no. of subjects")
[Link]'s online courses
n=int(input("Enter number of courses: "))
d={}
if n>=1:
for i in range(n):
print("Enter name of the subject and mark respectively:")
name=input()
mark=int(input())
if mark<0 or mark>100:
print("Invalid mark")
exit()
d[name]=mark
print("The courses you have cleared are:")
for key,value in [Link]():
if value>=80 and value<=100:
print(key,value)
else:
print("Invalid no. of courses")
[Link] names
names = []
print("Enter the number of names:")
number = int(input())
if(number<=0):
print("Invalid Input")
else:
print("Enter the names:")
for i in range(number):
name = input()
[Link](name)
[Link](reverse = True)
[Link](reverse=True,key=len)
print("The sorted name list is:")
for i in range(number):
print(names[i])
[Link] student data
n=int(input("Enter number of students: "))
file=open('output_data.txt','w')
for i in range(1,n+1):
print("Student"+str(i))
name=input("Enter name: ")
score=input("Enter the score: ")
line="Name: "+name+" "+"Score: "+score
[Link](line+"\n")
[Link]()
[Link] composer
def find_prime(start,end):
count=0
for num in range(start_number,end_number+1):
if num>1:
for i in range(2,num):
if(num%i)==0:
break
else:
print(num,end=" ")
count=count+1
if count==0:
print("There is no prime numbers in this range")
start_number=int(input())
end_number=int(input())
if start_number<0 or end_number<0 or start_number>end_number:
print("Invalid range")
elif start_number==end_number:
print("There is no prime numbers in this range")
else:
find_prime(start_number,end_number)
[Link] the file
print(
'''
Aerosol - 38
Churn - 50
Plank - 55
Slipsheet - 75
Jerrican - 950
Girder - 100
'''
)

You might also like