0% found this document useful (0 votes)
9 views4 pages

Python Programs for Beginners

The document contains a series of Python programming exercises designed to practice basic programming concepts. Each exercise includes a prompt and a sample code solution, covering topics such as BMI calculation, odd/even number checking, finding the largest of three numbers, arithmetic operations, and generating patterns. The exercises are intended for learners to enhance their coding skills through practical implementation.

Uploaded by

devhutigohel
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)
9 views4 pages

Python Programs for Beginners

The document contains a series of Python programming exercises designed to practice basic programming concepts. Each exercise includes a prompt and a sample code solution, covering topics such as BMI calculation, odd/even number checking, finding the largest of three numbers, arithmetic operations, and generating patterns. The exercises are intended for learners to enhance their coding skills through practical implementation.

Uploaded by

devhutigohel
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

Programs for Practical Notebook

August 10, 2024

[ ]: # [Link] a python program to calculate BMI of a person after inputting its␣


↪weight in kgs and height in metesr and print the nutritional status.

weight = int(input("Enter you weight in KGs :- "))


height = float(input("Enter you height in meters :- "))
bmi = (weight/(height**2))
print("Your BMI is :- ",bmi)
if (bmi<18.5):
print("Underweight")
elif (bmi<=24.9):
print("Normal")
elif (bmi<=29.9):
print("Overweight")
else:
print("Obese")

[ ]: # [Link] a python program that takes a number as input and checks whether the␣
↪number is odd or even.

n = int(input("Enter a number to check whether its odd or even :- "))


if (n%2!=0):
print(n,"is an odd number")
else:
print(n,"is an even number")

[ ]: # [Link] a python program to input three numbers and print the largest among␣
↪them.

n1 = int(input("Enter the First number :- "))


n2 = int(input("Enter the Second number :- "))
n3 = int(input("Enter the Third number :- "))
if (n1 >= n2 and n1>= n3):
print(n1,"is the greatest")
elif (n2 >= n3 and n2 >= n1):
print(n2,"is the greatest")
else:
print(n3,"is the greatest")

[ ]: # [Link] a python program to input 2 numbers along with an arithmetic␣


↪operator,and display the computed result.

1
n1 = int(input("Enter the First number :- "))
n2 = int(input("Enter the Second number :- "))
arithmetic_operator = input("Enter an arithmeti operator :- (ONLY +,-,*,/ and //
↪) ")

if (arithmetic_operator== '+'):
print(n1 + n2)
elif (arithmetic_operator == '-'):
print(n1 - n2)
elif (arithmetic_operator == '*'):
print(n1*n2)
elif (arithmetic_operator == '/'):
print(n1/n2)
elif (arithmetic_operator == '//'):
print(n1//n2)
else:
print("Wrong arithemtic operator")

[ ]: # [Link] a python code to print the mathematical table of a number using␣


↪while loop.

n = int(input("Enter a number to get it's mathemtical table :- "))


i = 1
while (i<=10):
print(n,"*",i,"=",n*i)
i+=1

[ ]: # [Link] a python code to print the sum of first n natural numbers using␣
↪while loop.

n = int(input("Enter a natural integer: "))


SUM = 0
i = 1
while (i <= n):
SUM += i
i += 1
print(f"The sum of the first",n," natural numbers is :-",SUM)

[ ]: # [Link] a python program to calculate and print the sum of the digits of a␣
↪number using while loop.

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


SUM= 0
while (n!=0):
digit = n % 10
SUM += digit
n //= 10
print("The sum of the digits is:",SUM)

[ ]: # [Link] a python code to print the sum of first even and odd natural numbers␣
↪using while loop.

2
n = int(input("Enter the number till which you want the sum of even and odd␣
↪numbers :- "))

i = 1
so = se = 0
while (i<=n):
if (i%2==0):
se+=i
else:
so+=i
i+=1
print("The sum of first",n," even natural numbers is :- ",se)
print("The sum of first",n," odd natural numbers is :- ",so)

[ ]: # [Link] a python program to print the first 20 elements of Fiboacci series.


↪(Some of the initial elements are:- 0,1,1,2,3,5,8,13......).

n = int(input("Enter the no. of elements of fibonacci series you want :- "))


first = 0
second = 1
for i in range(n):
third = first + second
print(third,end=" ")
first = second
second = third

[ ]: # [Link] a python program to print the following pattern:


# 1
# 1 3
# 1 3 5
# 1 3 5 7 .........
n = int(input("Enter the no. till which you want to make the pattern :- "))
for i in range(1,n+1,2):
for j in range(1,i+1,2):
print(j,end = " ")
print()

[ ]: # [Link] a python program to print the following pattern:


# 4 3 2 1
# 4 3 2
# 4 3
# 4
n = 4
for i in range(n,0,-1):
for j in range(n,n - i,-1):
print(j,end = " ")
print()

3
[ ]: # [Link] a python program to check if a given is armstrong number or not.
n = int(input("Enter a n. to check whether it is a armstrong no. or not :- "))
temp = n
SUM = 0
while (temp!= 0):
digit = temp % 10
SUM += (digit**3)
temp //= 10
if (n == SUM):
print("An Armstrong no.")
else:
print("Not an Armstrong no.")

You might also like