Sie sind auf Seite 1von 5

#Second hand books value

num=input("Enter the number of books to sell")


total=0; amt=0
for i in range(int(num)):
bookValue=input("Enter the value of the book")
total=total+int(bookValue)
amt=0.4*total
print("The total of the books is ", total)
print("The amount of money returned back after 40% cashback is ", amt)
#Vote eligibility
age=input("Enter your age")
if int(age) < 18:
print("Not eligible to vote")
else:
print("Eligible to vote")
#Even numbers
limit=int(input("Enter the limit"))
i=0
while i <= limit:
print(i)
i=i+2
#Get College name
clgname=input("Enter the string to get the college name")
if clgname!='ie':
print("Error")
exit()
else:
clgname = 'n' + clgname[0:]
print(clgname)
#Large of 2 numbers
num1 = input("Enter number 1\n")
num2 = input("Enter number 2")
if int(num1) > int(num2):
print(num1 + "is largest")
else:
print(num2 + "is largest")
#Large of 3 numbers
FirstNum=1
SecNum=4
LastNum=5
if(FirstNum > SecNum) and (FirstNum > LastNum):
print(FirstNum, "is largest")
else:
print(FirstNum, "is not largest")

#Array -> list sum of elements


my_array = [1,2,3,4,5]
print(my_array)
print(sum(my_array))
#marks card - single student
name=input("Enter the Name of the student\n")
m1=int(input("Enter marks in sub1\n"))
m2=int(input("Enter marks in sub2\n"))
m3=int(input("Enter marks in sub3\n"))
total=0
avg=0
if m1 < 40 or m2 < 40 or m3 < 40:
print(name + " Sorry you did not pass")
exit()
else:
total=m1+m2+m3
avg=total/3
print(name + " Your Total is ", total)
print(name + " Your Average is ", avg)
#multiples of 3
limit=int(input("Enter the limit"))
i=3
while i<limit:
if i % 3 == 0:
print(i)
i=i+1
#marks card - n students
num=input("Enter the number of students")
for i in range(int(num)):
name=input("Enter the Name of the student\n")
m1=int(input("Enter marks in sub1\n"))
m2=int(input("Enter marks in sub2\n"))
m3=int(input("Enter marks in sub3\n"))
total=0
avg=0
if m1 > 40 and m2 > 40 and m3 > 40:
total=m1+m2+m3
avg=total/3
print(name + " Your Total is ", total)
print(name + " Your Average is ", avg)
else:
print(name + " Sorry you did not pass")
#square root of a number

import math
num=int(input("Enter the number"))
print(math.sqrt(num))
#valid name on length
name=input("Enter your name")
if len(name) > 10:
print("Invalid name")
else:
print("valid name")
#to print localtime
import time
localtime = time.asctime(time.localtime(time.time()))
print ("the local time is" , localtime)
#print june2015 calendar
import calendar
cal = calendar.month(2015,6)
print(cal)
#Script to print a message
#get Hour
from datetime import datetime
currentHour = datetime.now().hour
if currentHour > 16 and currentHour < 20:
print("Good Evening")
#check if current year is leap year
from datetime import datetime
import calendar
currentYear=datetime.now().year;
tf=calendar.isleap(currentYear)
if tf:
print(currentYear , " is a leap year")
else:
print(currentYear , " is not a leap year")
#input year to see if the year is a leap year or not
import calendar

yearInp=int(input("Enter the year"))


info = calendar.isleap(yearInp)
print(info)
if info:
print(yearInp, " is a leap year")
else:
print(yearInp, " is not a leap year")
print("Python script to add 2numbers")
def add(num1,num2):
sum1=num1+num2
#
print(sum1)
return sum1
a=add(2,3)
print(a)
#switch dict
def f(x):
return {
'a': 1,
'b': 2,
}.get(x, 9)
f(a)
#perform basic arithmetic operations using functions
#addition
def add():
n1=int(input("Enter num1"))
n2=int(input("Enter num1"))
return n1+n2
#subtraction
def sub():
n1=int(input("Enter num1"))
n2=int(input("Enter num1"))
return n1-n2
a=add()
print("sum is ", a)
b=sub()
print("diff is ", b)

#!/usr/bin/python
# Function definition is here
def printinfo( arg1, *vartuple ):
#"This prints a variable passed arguments"
print( "Output is: ")
print(arg1)
for var in vartuple:
print( var)
return;
# Now you can call printinfo function
printinfo( 10 );
printinfo( 70, 60, 50 );
#variable args addition
def add(*variable):
sum1=0
for var in variable:
sum1=sum1+var
print(sum1)
add(1,2,3)
#anonymous functions
prod = lambda a1,a2:a1*a2
print("product is", prod(2,3))