0% found this document useful (0 votes)
40 views10 pages

Biology

The document contains 20 code snippets demonstrating various Python programming concepts like input/output, conditional statements, loops, functions, lists, dictionaries, strings and more. The code snippets include programs to calculate simple interest, check if a number is even or odd, check if a year is a leap year, calculate factorial of a number, print numbers divisible by 5 between 1-100, find LCM of two numbers, check if a number is perfect, check if a number is Armstrong, check if a number is palindrome, check if a number is prime, convert decimal to binary using recursion, print star patterns, print Fibonacci series, count characters in a string, check if a string is palindrome, find minimum element in a list,

Uploaded by

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

Biology

The document contains 20 code snippets demonstrating various Python programming concepts like input/output, conditional statements, loops, functions, lists, dictionaries, strings and more. The code snippets include programs to calculate simple interest, check if a number is even or odd, check if a year is a leap year, calculate factorial of a number, print numbers divisible by 5 between 1-100, find LCM of two numbers, check if a number is perfect, check if a number is Armstrong, check if a number is palindrome, check if a number is prime, convert decimal to binary using recursion, print star patterns, print Fibonacci series, count characters in a string, check if a string is palindrome, find minimum element in a list,

Uploaded by

rishab ghosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

`P = float(input("Enter the principal amount : "))

N = float(input("Enter the number of years : "))

R = float(input("Enter the rate of interest : "))

#calculate simple interest by using this formula


SI = (P * N * R)/100

#print
print("Simple interest : {}".format(SI))

1)

2)
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even number". format(num))
else:
print("{0} is Odd number". format(num))

3)
year = int(input('Enter year : '))
 
if (year%4 == 0 and year%100 != 0) or (year%400 == 0) :
    print(year, "is a leap year.")
else :
    print(year, "is not a leap year.")

5.
num = int(input("Enter a number: "))    
factorial = 1    
if num < 0:    
   print(" Factorial does not exist for negative numbers")    
elif num == 0:    
   print("The factorial of 0 is 1")    
else:    
   for i in range(1,num + 1):    
       factorial = factorial*i    
    print("The factorial of",num,"is",factorial)    

6)

for i in range(1,101):
if(i%5==0):
print(i)

7)

num1 = int(input("Enter a number: ")
num2 = int(input("Enter a number: ")
for i in range(max(num1, num2), 1 + (num1 * num2)):
if i % num1 == i % num2 == 0:
lcm = i
break
print("LCM of", num1, "and", num2, "is", lcm)

8)

n = int(input("Enter any number: "))


sum1 = 0
for i in range(1, n):
if(n % i == 0):
sum1 = sum1 + i
if (sum1 == n):
print("The number is a Perfect number!")
else:
print("The number is not a Perfect number!")

9)
n = int(input("Enter a number: "))

#initialize the sum

s = 0

t = n

while t > 0:

digit = t % 10

s += digit ** 3

t //= 10

# display the result

if n == s:

print(n,"is an Armstrong number")

else:

print(n,"is not an Armstrong number")

10)

n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")

11)

n= int(input("Enter any number:"))


if(n ==0 or n == 1):
    printf(n,"Number is neither prime nor composite")
elif n>1 :
    for i in range(2,n):
        if(n%i == 0):
            print(n,"is not prime but composite number")
            break
    else:
        print(n,"number is prime but not composite number")
else :
    print("Please enter positive number only ")

12)

# Function to convert decimal number

# to binary using recursion

def DecimalToBinary(num):

if num >= 1:

DecimalToBinary(num // 2)

print(num % 2, end = '')

# Driver Code

if __name__ == '__main__':

# decimal value

dec_val = 24
# Calling function

DecimalToBinary(dec_val)

13)

#Program to print Left Half Pyramid


num_rows = int(input("Enter the number of rows"));
k = 1
for i in range(0, num_rows):
for j in range(0, k):
print("* ", end="")
k = k + 1
print()

print("Program to print star pattern in different style: \n");


num_rows = int(input('Please enter the number of rows'));
for i in range (0,num_rows):
for j in range (num_rows,i,-1):
print("* ", end="")
print()

#Program to print Right Half Pyramid


num_rows = int(input("Enter the number of rows"));
k = 8
for i in range(0, num_rows):
for j in range(0, k):
print(end=" ")
k = k - 2
for j in range(0, i+1):
print("* ", end="")
print()

rows = 5
i = rows
while i >= 1:
j = rows
while j > i:
# display space
print(' ', end=' ')
j -= 1
k = 1
while k <= i:
print('*', end=' ')
k += 1
print()
i -= 1

14
num = 10
n1, n2 = 0, 1
print("Fibonacci Series:", n1, n2, end=" ")
for i in range(2, num):
n3 = n1 + n2
n1 = n2
n2 = n3
print(n3, end=" ")

print()

15)

s = input("Enter any string :")


vowel = consonent = uppercase = lowercase= 0
for i in s:
    if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'or i == 'A' or i ==
'E' or i == 'I' or i == 'O' or i == 'U'):
         vowel = vowel +1
    else:
         consonent = consonent + 1
    if i.isupper() :
        uppercase = uppercase + 1
         
    if i.islower():
        lowercase = lowercase + 1
         
print("Total number of vowel:",vowel)
print("Total number of consonent:",consonent)
print("Total number of uppercase letter:",uppercase)
print("Total number of lowercase letter:",lowercase)

16)

s = input("Enter any string :")


j = -1
flag = 0
for i in s:
   if i != s[j]:
        flag = 1
        break
   j = j - 1
if flag == 1:
    print(s,"--> This string is not palindrome")
else:
    print(s,"--> This string is palindrome")
sc = s.swapcase()
print("String after converting the case of each character :",sc)

17)

list1 = []
# Input number of elements to put in list
num = int(input("Enter number of elements in list: "))
# iterating till num to append elements in list
for i in range(1, num + 1):
element= int(input("Enter elements: "))
list1.append(element)
# print Smallest element
print("Smallest element in List1 is:", min(list1))

18)

# Entering 5 element Lsit


mylist = []
print("Enter 5 elements for the list: ")
for i in range(5):
value = int(input())
mylist.append(value)
# printing original list
print("The original list : " + str(mylist))
# Separating odd and even index elements
odd_i = []
even_i = []
for i in range(0, len(mylist)):
if i % 2:
even_i.append(mylist[i])
else :
odd_i.append(mylist[i])
result = odd_i + even_i
# print result
print("Separated odd and even index list: " + str(result))

19)

mylist = []
print("Enter 5 elements for the list: ")
for i in range(5):
value = int(input())
mylist.append(value)
print("Enter an element to be search: ")
element = int(input())
for i in range(5):
if element == mylist[i]:
print("\nElement found at Index:", i)
print("Element found at Position:", i+1)

20)

no_of_std = int(input("Enter number of students: "))


result = {}
for i in range(no_of_std):
print("Enter Details of student No.", i+1)
roll_no = int(input("Roll No: "))
std_name = input("Student Name: ")
marks = int(input("Marks: "))
result[roll_no] = [std_name, marks]
print(result)
# Display names of students who have got marks more than 75
for student in result:
if result[student][1] > 75:
print("Student's name who get more than 75 marks is/are",(result[student][0]))

4) print("Enter Marks Obtained in 5 Subjects: ")

markOne = int(input())

markTwo = int(input())

markThree = int(input())

markFour = int(input())

markFive = int(input())

tot = markOne+markTwo+markThree+markFour+markFive

avg = tot/5

if avg>=91 and avg<=100:

print("Your Grade is A1")

elif avg>=81 and avg<91:

print("Your Grade is A2")

elif avg>=71 and avg<81:

print("Your Grade is B1")


elif avg>=61 and avg<71:

print("Your Grade is B2")

elif avg>=51 and avg<61:

print("Your Grade is C1")

elif avg>=41 and avg<51:

print("Your Grade is C2")

elif avg>=33 and avg<41:

print("Your Grade is D")

elif avg>=21 and avg<33:

print("Your Grade is E1")

elif avg>=0 and avg<21:

print("Your Grade is E2")

else:

print("Invalid Input!")

You might also like