0% found this document useful (0 votes)
7 views

15 BASIC PYTON PROGRAMS by Shashwat Singh Class q10 C

Uploaded by

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

15 BASIC PYTON PROGRAMS by Shashwat Singh Class q10 C

Uploaded by

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

N

T O
PY
I C S
A S M
B RA
5
1 O G
PR
BY
S H A S H WAT
SINGH
10 C
ROLL_NO_24
ODD OR EVEN
• number = 7
• if number % 2 == 0:
• print("Even")
• else:
• print("Odd")
OUTPUT
• Odd
FRACTORIAL OF A NUMBER
• def factorial(n):
• if n == 0:
• return 1
• else:
• return n * factorial(n-1)

• print("Factorial of 5:", factorial(5))


OUTPUT
• Factorial of 5: 120
ADDITION
• a=5
• b=3
• sum = a + b
• print("Sum:", sum)
OUTPUT
• Sum: 8
PRIME NUMBER CHECK
• num = 29
• is_prime = True
• for i in range(2, int(num**0.5) + 1):
• if num % i == 0:
• is_prime = False
• break
• print(num, "is prime:", is_prime)
OUTPUT
• 29 is prime: True
FIND THE LARGEST AMONG THE THREE
• a, b, c = 10, 20, 15
• largest = max(a, b, c)
• print("Largest number:", largest)
OUTPUT
• Largest number: 20
COUNTING WORD IN A SENTENCE
• sentence = "Python is fun and easy"
• word_count = len(sentence. split())
• print("Number of words:", word_count)
OUTPUT
• Number of words: 5
SUM OF NATURAL NUMBER
• n = 10
• sum_n = sum(range(1, n + 1))
• print("Sum of first", n, "natural numbers:",
sum_n)
OUTPUT
• Sum of first 10 natural numbers: 55
AREA OF A CIRCLE
• import math
• radius = 7
• area = math.pi * radius ** 2
• print("Area of the circle:", area)
OUTPUT
• Area of the circle: 153.93804002589985
GERNATE A RANDOM NUMBER
• import random
• random_number = random.randint(1, 100)
• print("Random number between 1 and 100:",
random_number)
OUTPUT
• Random number between 1 and 100: 42
(Output will vary)
CALCULATE AREA OF RECTRANGLE
• length = 5
• width = 3
• area = length * width
• print("Area of rectangle:", area)
OUTPUT
• Area of rectangle: 15
PRINT DAYS OF WEEK
• days = ["Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday"]
• for day in days:
• print(day)
OUTPUT
• Monday
• Tuesday
• Wednesday
• Thursday
• Friday
• Saturday
• Sunday
MULTIPLY TWO NUMBER
• a=4
• b=5
• product = a * b
• print("Product:", product)
OUTPUT
• Product: 20
SIMPLE QUIZ
• answer = input("What is 2 + 2? ")
• if answer == "4":
• print("Correct!")
• else:
• print("Try again.")
OUTPUT
• What is 2 + 2? 4
• Correct!
DRAW A SQUARE
• for i in range(4):
• print("* " * 5)
OUTPUT
• *****
• *****
• *****
• *****

You might also like