0% found this document useful (0 votes)
58 views12 pages

Computer Science Practical Project

The document contains 15 Python programs with examples to demonstrate various programming concepts like input/output, arithmetic operations, conditional statements, loops, functions, lists, random numbers and more. Each program is presented with sample input, code and output. The programs cover basic concepts like Hello World, calculator, even/odd checker to more complex ones like prime number checker, random number generator, list operations and string processing.

Uploaded by

Krish Arora
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)
58 views12 pages

Computer Science Practical Project

The document contains 15 Python programs with examples to demonstrate various programming concepts like input/output, arithmetic operations, conditional statements, loops, functions, lists, random numbers and more. Each program is presented with sample input, code and output. The programs cover basic concepts like Hello World, calculator, even/odd checker to more complex ones like prime number checker, random number generator, list operations and string processing.

Uploaded by

Krish Arora
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/ 12

KRISH ARORA

1. Python Programs
i. Hello, World!
Input
print(“Hello, World!”)
Output
Hello, World!

ii. Calculator- Addition


Input
num1 = float(input(“Enter the first number: “))
num2 = float(input(“Enter the second number: “))
result = num1 + num2
print(“Result: “, result)
Output
Enter the first number: 1
Enter the second number: 2
Result: 3.0 iii. Even or Odd
number Checker

Input
Num = int(input(“Enter a number:
“)) if num % 2 == 0: print(“Even”)
else:
print(“Odd”)
Output
Enter a number: 1
Odd
Enter a number: 8
Even

iv.
Sum of Digits in a Number
Input
num = int(input(“Enter a number: “))
digit_sum = sum(int(digit) for digit in str(num))
print(“Sum of digits: “, digit_sum)
Output
Enter a number: 143
Sum of digits: 3
v. Square of a number

Input
num = float(input(“Enter a number:
”)) square = num**2 print(“Square: “,
square)

Output
Enter a number: 5
Square: 25.0

vi.

Factorial Calculator
Input
num = int(input(“Enter a number:
“)) factorial = 1 for i in range(1, num
+ 1): factorial *= i
print(“Factorial: “, factorial)
Output
Enter a number: 8
Factorial: 40320
vii.
Count Vowels in a string
Input
text = input(“Enter a string: “).lower()
vowel_count = sum(1 for char in text if char in ‘aeiou’ )
print(“Vowel count: “, vowel_count)

Output
Enter a string: Rishi
Vowel count: 2

viii. Check for a Palindrome


Input
word = input(“Enter a word: “)
if word == word[::-1]:
print(“It’s a palindrome!”)
else:

print(“It’s not a palindrome.”)


Output
Enter a word: Krish Its
not a palindrome.
ix.
Simple for loop
Input for i in
range(1,6):
print(i)
Output
1
2
3
4
5
6

x.
List of squares
Input
numbers = [1, 2, 3, 4, 5] squares
= [x**2 for x in numbers]
print(“Squares: “, suqares)
Output
Squares: [1, 4, 9, 16, 25]

xi. Sum of a list


Input
numbers = [1, 2, 3, 4, 5,]
total = sum(numbers)
print(“Sum: “, total)
Output
Sum: 15

xii.
Check for prime number

Input
num = int(input(“Enter a number: “))
is_prime = all(num % I !=0 for I in range(2, num)) if
is_prime:
print(“It’s a prime number.”)
else:
print(“Its not a prime number.”)

Output
Enter a number: 18
Its not a prime number.
xiii. Generate Random Number
Input

import random
random_num = random.randint(1, 100)
print(“Random number: “, random_num)
Output
Random number: 15

xiv.
Simple while loop
Import count= 1
while count <=
5:
print(count)
count += 1
Output
1
2
3
4
5
xv. Greet the user
Input
Name = input(“Enter your name: “)
Print(“Hello, “+ name + “!”)
Output
Enter your name: Karan Hello,
Karan!

You might also like