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

A Int (Input ('Enter First Number: ') ) B Int (Input ('Enter Second Number: ') ) If A B: Print ('Largest Is', A) Else: Print ('Largest Is', B)

Chemistry salt analysis

Uploaded by

nilo.parveen
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)
23 views4 pages

A Int (Input ('Enter First Number: ') ) B Int (Input ('Enter Second Number: ') ) If A B: Print ('Largest Is', A) Else: Print ('Largest Is', B)

Chemistry salt analysis

Uploaded by

nilo.parveen
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/ 4

COMPUTER SCIENCE

PROGRAMS LIST - GRADE 11

# Program 1: Read two numbers from the user and display the largest/smallest number

a = int(input('Enter first number: '))


b = int(input('Enter second number: '))
if a > b:
print('Largest is', a)
else:
print('Largest is', b)

Output:
Enter first number: 45
Enter second number: 23
Largest is 45

#Program 2:
# Read two numbers from the user and display the odd/even number.
# Add 1 to even and subtract 1 from odd.

def odd_even(num):
if num % 2 == 0:
print(num, 'is even.')
num += 1
else:
print(num, 'is odd.')
num -= 1
print('New number:', num)
a = int(input('Enter first number: '))
b = int(input('Enter second number: '))
odd_even(a)
odd_even(b)

Output:
Enter first number: 6
Enter second number: -8
6 is even.
New number: 7
-8 is even.
New number: -7
#Program 3:
# Find the area of a 2D shape (square, rectangle, triangle, circle)

from math import pi

choice = int(input('Choose the shape to find the area of:\n1. Square\n2. Rectangle\n3.
Triangle\n4. Circle\n'))
if choice == 1:
side = int(input('Enter the side:'))
print('Area of a square with side', side, 'is', side * side)
elif choice == 2:
length = int(input('Enter the length:'))
breadth = int(input('Enter the breadth:'))
print('Area of rectangle with length', length, 'and breadth', breadth, 'is', length * breadth)
elif choice == 3:
base = int(input('Enter the base:'))
height = int(input('Enter the height:'))
print('Area of triangle with base', base, 'and height', height, 'is', 0.5 * base * height)
elif choice == 4:
radius = int(input('Enter the radius:'))
print('Area of a circle with radius', radius, 'is', round(pi * radius * radius, 2))
else:
print('Invalid choice.')

Output:
Choose the shape to find the area of:
1. Square
2. Rectangle
3. Triangle
4. Circle

1
Enter the side:3
Area of a square with side 3 is 9

2
Enter the length:2
Enter the breadth:5
Area of rectangle with length 2 and breadth 5 is
10

3
Enter the base:5
Enter the height:8
Area of triangle with base 5 and height 8 is 20.0
4
Enter the radius:4
Area of a circle with radius 4 is 50.27

#Program 4:
# Read two numbers from the user and compute x power n

x = int(input('Enter number: '))


n = int(input('Enter power: '))
print(x, 'raised to', n, 'is', x ** n)

Output:
Enter number: 5
Enter power: 3
5 raised to 3 is 125

#Program 5:
# Program that displays first 9 terms of Fibonacci series

n1 = -1
n2 = 1
print('First 9 Fibonacci terms are:')
for i in range(1, 10):
n3 = n1 + n2
print(n3, end=' ')
n1 = n2
n2 = n3
print()

Output:
First 9 Fibonacci terms are:
0 1 1 2 3 5 8 13 21

#Program 6:
#Program to read a string and replace all the spaces with "_".

mystring = input('Enter a string: ')


newstring = ''
for char in mystring:
if char == ' ':
newstring += '_'
else:
newstring += char

print('The new string is', newstring)

Output:

Enter a string: Vyasa International School


The new string is Vyasa_International_School

#Program 7:
#Program to read a string and check if it is a palindrome.

mystring = input('Enter a string: ')


if mystring == mystring[::-1]:
print(mystring, 'is a palindrome.')
else:
print(mystring, 'is not a palindrome.')

Output:

Enter a string: racecar


racecar is a palindrome.

Enter a string: vyasa


vyasa is not a palindrome.

************

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy