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

Python Program For Class 9

The document contains a series of Python code snippets demonstrating various programming concepts such as basic input/output, arithmetic operations, conditional statements, and functions. It includes examples for calculating the cube of a number, the area of a rectangle, and checking for Armstrong numbers, among others. Additionally, it features a Fibonacci sequence generator and a program to calculate the combined workdays of three individuals.

Uploaded by

lakshyakhatana38
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)
7 views4 pages

Python Program For Class 9

The document contains a series of Python code snippets demonstrating various programming concepts such as basic input/output, arithmetic operations, conditional statements, and functions. It includes examples for calculating the cube of a number, the area of a rectangle, and checking for Armstrong numbers, among others. Additionally, it features a Fibonacci sequence generator and a program to calculate the combined workdays of three individuals.

Uploaded by

lakshyakhatana38
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

name="Rehman"

print("Greetings")

print("Hello",name)

print("How do you do?")

print(14//4, 14%4, 14/4)

print(2*'No' +3*'!')

print(2*('No' +3*'!'))

myset={1,2,3,4}

print(myset)

#program to find out Cube of Number


num=int(input("Enter a number : "))
cube=num*num*num OR num**3
print("Number is ",num)
print("Its cube is ",cube)
#to input length and breadth of rectangle and calculate its area
length=float(input("Enter length of rectangle:"))
breadth=float(input("Enter breadth of rectangle:"))
area=length*breadth
print("Area=", area)
a=int(input("Enter 1st no"))
b=int(input("Enter 2nd no "))
s=a+b
p=a*b
if(a>b):
d=a-b
else:
d=b-a
print("Sum=7",s)
print("Product=12",p)
print("Difference=1",d)

name=input("Enter name ")


age=int(input("Enter age "))
if(age>=18):
print("you can vote")
else:
print("you cannot vote")

import math

a,b,c=17,23,30

s=(a+b+c)/2

area=[Link](s*(s-a)*(s-b)*(s-c))

print("sides of triangle:",a,b,c)

print("area:",area,"units square")

Write a prpgram to calculate how many days a work will be completed by three persons A,B and C together

x=int(input("Enter value of x"))


y=int(input("Enter value of y"))
z=int(input("Enter value of z"))
print("Individually,A,B and C take days respectively as:",x,y,z)
days=(x*y*z)/(x*y*z+x*z)
print("Together A,B and C take days as:",days)
# Python program to check if the number is an Armstrong number or not

# take input from the user


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

# initialize sum
sum = 0

# find the sum of the cube of each digit


temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10

# display the result


if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Run Code

Output 1

Enter a number: 663


663 is not an Armstrong number

Output 2

Enter a number: 407


407 is an Armstrong number

n = 10
num1 = 0
num2 = 1
next_number = num2
count = 1
while count <= n:
print(next_number, end=" ")
count += 1 count = count+1
num1, num2 = num2, next_number
next_number = num1 + num2
print()
n num1 num2 next_number count output
10 0 1 1 1 1
1 1 2 2 2

You might also like