0% found this document useful (0 votes)
42 views20 pages

CS Project

This document contains 20 programming questions and their solutions in Python. Each question includes the source code to solve the problem, followed by sample output. The questions cover a variety of basic programming concepts like arithmetic operations, conditional statements, loops, functions, strings, lists, random numbers, and more.

Uploaded by

sounavaaa29138
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)
42 views20 pages

CS Project

This document contains 20 programming questions and their solutions in Python. Each question includes the source code to solve the problem, followed by sample output. The questions cover a variety of basic programming concepts like arithmetic operations, conditional statements, loops, functions, strings, lists, random numbers, and more.

Uploaded by

sounavaaa29138
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
You are on page 1/ 20

Q.

1 Add two numbersS

Source code :
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum:", a + b)

Output :
Q.2 Find Maximum of Two Numbers

Source Code :

a, b = map(int, input("Enter two numbers separated by space:


").split())
print("Maximum:", max(a, b))

Output :
Q.3 Calculate Area of a Circle

Source Code :

radius = float(input("Enter the radius: "))


area = 3.141592653589793 * radius * radius
print("Area:", area)

Output :
Q.4 Swap Two Variables

Source Code :

a, b = 5, 10
a, b = b, a
print("a:", a, "b:", b)

Output :
Q.5 Check if Number is Odd or Even

Source Code :

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


print("Even" if num % 2 == 0 else "Odd")

Output :
Q.6 Reverse a String

Source Code :

s = input("Enter a string: ")


print("Reversed:", s[::-1])

Output :
Q.7 Find Factorial of a Number

Source Code :
def factorial(n):
return 1 if n == 0 else n * factorial(n-1)

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


print("Factorial:", factorial(num))

Output :
Q.8 Check if a Number is Prime

Source Code :
num = int(input("Enter a number: "))
for i in range(2, int(num**0.5)+1):
if num % i == 0:
print("Not Prime")
break
else:
print("Prime")

Output :
Q.9 Simple Calculator (Addition and Subtraction)

Source Code :
a, b = map(int, input("Enter two numbers separated by space:
").split())
op = input("Enter opera on (+ or -): ")
print(a+b if op == '+' else a-b)

Output :
Q.10 Generate Fibonacci Series (first 10 numbers)

Source Code :
a, b = 0, 1
for _ in range(10):
print(a, end=' ')
a, b = b, a + b

Output :
Q.11 Print All Multiples of a Number (up to 100)

Source Code :
num = int(input("Enter a number: "))
for i in range(1, 101):
if i % num == 0:
print(i)
Output :
Q.12 Convert Celsius to Fahrenheit

Source Code :
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = 1.8 * celsius + 32
print("Temperature in Fahrenheit:", fahrenheit)

Output :
Q.13 Simple Interest Calculator

Source Code :
p = float(input("Enter principal amount: "))
r = float(input("Enter rate of interest (in %): "))
t = float(input("Enter me (in years): "))
si = (p * r * t) / 100
print("Simple Interest:", si)

Output :
Q.14 Check if a String is a Palindrome

Source Code :
s = input("Enter a string: ")
print("Palindrome" if s == s[::-1] else "Not Palindrome")

Output :
Q.15 Print Star Pattern

Source Code :
n = int(input("Enter number of rows: "))
for i in range(n):
print('*' * (i+1))

Output :
Q.16 Calculate Average of Numbers in a List

Source Code :
numbers = [int(x) for x in input("Enter numbers separated by space:
").split()]
average = sum(numbers) / len(numbers)
print("Average:", average)

Output :
Q.17 Find the Smallest Number in a List

Source Code :
numbers = [int(x) for x in input("Enter numbers separated by space:
").split()]
print("Smallest:", min(numbers))

Output :
Q.18 Count Vowels in a String

Source Code :
s = input("Enter a string: ").lower()
vowels = 'aeiou'
count = sum(1 for char in s if char in vowels)
print("Number of vowels:", count)

Output :
Q.19 Guess the Number Game

Source Code :
import random
number = random.randint(1, 100)
for _ in range(5):
guess = int(input("Guess the number (1-100): "))
if guess == number:
print("You guessed it!")
break
print("Too high" if guess > number else "Too low")
else:
print("Sorry, out of a empts. The number was:", number)

Output :
Q.20 Hello World

Source Code :

print("Hello, World!")

Output :

You might also like