0% found this document useful (0 votes)
19 views3 pages

100 Python Programs for Beginners

It will be super

Uploaded by

tsaketh32
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

100 Python Programs for Beginners

It will be super

Uploaded by

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

Python Programs

#1 A python program to perform arithmetic operations


a=int(input("Enter a value for a: "))
b=int(input("Enter a value for b: "))
sum=a+b
sub=a-b
mul=a*b
div=a/b
fd=a//b
md=a%b
pow=a**b
print("The sum of a & b is :",sum)
print("The subtraction of a & b is :",sub)
print("The product of a & b is :",mul)
print("The division of a & b :",div)
print("The floor division of a & b" ,fd)
print("The modulus division of a & b:",md)
print("The power of a & b is : ",pow)

#2 A python program to print multiplication table for the given number


num = int(input("Enter a number to print that multiplication table: "))
i=1
while i<=10:
print(num,"X",i,"=",num*i)
i=i+1
print("Thank you have a nice day")

#3 A python program to print a given number is leap year or not


year = int(input("Enter an year to check it is leap year or not: "))
if year%4 == 0:
print("The given year is leap year")
else:
print("The given year is not a leap year")

#4 A python program to swap two numbers without using the third variable
a=int(input("Enter a value for a: "))
b=int(input("Enter a value for b: "))
print("The value of a before swap :",a)
print("The value of b before swap :",b)
a=a+b
b=a-b
a=a-b
print("The value of a after swap =",a)
print("The value of b after swap =",b)

#5 A python program to swap two numbers by using the third variable


a=int(input("Enter a value for a: "))
b=int(input("Enter a value for b: "))
print("The value of a before swap :",a)
print("The value of b before swap :",b)
t=a
a=b
b=t
print("The value of a after swap :",a)
print("The value of b after swap :",b)

#6 A python program to check the given number is palindrome or not


num = int(input("Enter a number to check the given number is palindrome or not :"))
n=num
palin=0
while n>0:
x=n%10
palin = palin*10 + x
n=n//10
if palin==num:
print("The given number is palindrome")
else:
print("The given number is not palindrome")

#7 A python program to print either odd or even numbers upto the numbers you want
n=int(input("Enter upto how many numbers you want? "))
ch=input("Enter your choice to print either odd or even numbers? Type O for ODD and E for Even: ")
if ch=='O' or ch=='o':
i=0
while i<=n:
if i%2==1:
print(i)
i=i+1
elif ch=='E' or ch=='e':
i=1
while i<=n:
if i%2==0:
print(i)
i=i+1
else:
print("You have choosen a wrong one! Thank you.")

#8 A python program to print factorial of a given number


n=int(input("Enter which factorial do you want? : "))
fact=1
i=1
while i<=n:
fact=fact*i
i=i+1
print("The factorial of a given number is :",fact)

#9 A python program to print Weekday of the month based upon the code
ch=input("Enter the weekday code : sun, mon, tue, wed, thu, fri, sat:")
if ch == 'sun' or 'SUN':
print("Its Sunday!")
elif ch == 'mon' or 'MON':
print("Its Monday!")
elif ch == 'tue' or 'TUE':
print("Its Tuesday!")
elif ch == 'wed' or 'WED':
print("Its Wednesday!")
elif ch == 'thu'or 'THU':
print("Its Thursday!")
elif ch == 'fri' or 'FRI':
print("Its Friday!")
elif ch == 'sat' or 'SAT':
print("Its Saturday!")
else:
print("You have entered a wrong weekday code!")
print("Try again...")

#10 A python program to print biggest of three numbers


a=int(input("Enter a value for a: "))
b=int(input("Enter a value for b: "))
c=int(input("Enter a value for c: "))
if a>b and a>c:
print("The value of A is bigger")
elif a==b==c:
print("All the values of A, B and C are same")
elif b>c:
print("The vlaue if B is bigger")
else:
print("The value of C is bigger")

#11 A python program to print a pattern of numbers in right-angled


n=int(input("Enter a value for n: "))
for i in range(1,n):
j=i
while j<=n:
print(j,end=" ")
j=j+1
print()

#12 A python program to print a pattern of numbers in right-angled


n=int(input("Enter a value for n: "))
for i in range(1, n + 1):
for j in range(1, i + 1):
print(j, end=" ")
print()

Note: Try by placing * (asterisk) sign and check out the output for #11 and #12 programs

You might also like