Python File12
Python File12
Submitted By Submitted To
Poonam Devi Keshav Sir
20MCA01
1)Program for Arithmetic Operations in Python
Source code:
val1 = 2
val2 = 3
print(res)
val1 = 2
val2 = 3
print(res)
val1 = 2
val2 = 3
print(res)
val1 = 3
val2 = 2
print(res)
val1 = 3
val2 = 2
print(res)
val1 = 2
val2 = 3
print(res)
val1 = 3
val2 = 2
print(res)
Output:
2)Program to Generate a Random Number
Source code:
import random
print(random.randint(0,9))
Output:
3) Program to Convert Celsius To Fahrenheit
Source code:
# given formula
%(celsius_1, Fahrenheit_1))
print("----OR----")
%(celsius_2, Fahrenheit_2))
Output:
4) Python Program to Check if a Number is Positive, Negative or zero
Source code:
def NumberCheck(a):
if a > 0:
elif a < 0:
else:
# Printing result
NumberCheck(a)
Output:
5) Python Program to Check if a Number is Odd or Even
Source code:
if (num % 2) == 0:
else:
Output:
6)Python Program to Check Leap Year
Source code:
def CheckLeap(Year):
if((Year % 400 == 0) or
(Year % 4 == 0)):
else:
# Printing result
CheckLeap(Year)
Output:
7)Python Program to Find ASCII Value of given Character
Source code:
c = 'g'
Output:
8)Python program to print grades based on marks scored by a student
Source code:
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A")
elif(avg>=80&avg<90):
print("Grade: B")
elif(avg>=70&avg<80):
print("Grade: C")
elif(avg>=60&avg<70):
print("Grade: D")
else:
print("Grade: F")
Output:
9) Python program to print the sum of all numbers in the given range
Source code:
n = int (n)
sum = 0.
sum = sum+num.
Output:
10) Python program to print all even numbers in given range
Source code:
# iteration
# check
if num % 2 == 0:
Output:
11)Python program to print star pyramid pattern
Source code:
def triangle(n):
# number of spaces
k=n-1
print(end=" ")
k=k-1
print("\r")
# Driver Code
n=5
triangle(n)
Output:
12)Python program to print number pyramid pattern
Source code:
def pypart(n):
myList = []
for i in range(1,n+1):
myList.append("*"*i)
print("\n".join(myList))
# Driver Code
n=5
pypart(n)
Output:
13)Python program to print Fibonacci numbers to given limit
Source code:
def Fibonacci(n):
if n < 0:
print("Incorrect input")
# Check if n is 0
elif n == 0:
return 0
# Check if n is 1,2
# it will return 1
elif n == 1 or n == 2:
return 1
else:
# Driver Program
print(Fibonacci(9))
Output:
14) Python program to print numbers from 1 to n except 5 multiples
Source code:
for a in range(1,10):
if a % 5 != 0:
print(a)
Output:
15)Python program to split and join a string
Source code:
def split_string(string):
return list_string
def join_string(list_string):
string = '-'.join(list_string)
return string
# Splitting a string
list_string = split_string(string)
res_string = join_string(list_string)
Output: