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

Cs File

The document contains a Python script that prompts users for input and performs various calculations including comparisons, number patterns, series summation, and checks for palindromes, Armstrong numbers, perfect numbers, prime numbers, and GCD/LCM. It also includes functionality to create a student data dictionary and analyze strings for character counts. The script demonstrates fundamental programming concepts such as loops, conditionals, and data structures.

Uploaded by

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

Cs File

The document contains a Python script that prompts users for input and performs various calculations including comparisons, number patterns, series summation, and checks for palindromes, Armstrong numbers, perfect numbers, prime numbers, and GCD/LCM. It also includes functionality to create a student data dictionary and analyze strings for character counts. The script demonstrates fundamental programming concepts such as loops, conditionals, and data structures.

Uploaded by

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

m=input("enter welcome message")

print(m)

a=int(input("enter number"))
b=int(input("enter number"))
if a>b:
print("a is greater")
else:
print("b is greater")

a=int(input("enter number"))
b=int(input("enter number"))
c=int(input("enter number"))
if a>b and a>c:
print("a is greatest")
elif b>a and b>c:
print("b is greatest")
else:
print("c is greatest")

for i in range(1,6):
for j in range(0,i):
print("*",end="")
print()

for i in range(5,0,-1):
for j in range(1,i+1):
print(j,end="")
print()

for i in range(1,6):
s=65
for j in range(0,i):
print(chr(s),end="")
s=s+1
print()

#1+x+x^2+x^3+x^4+ ............x^n

import math
x = int(input("Enter value of x:"))
n=int(input("Enter value of n:"))
s=0
for i in range(n+1):
k=math.pow(x,i)
s+=k
print("answer is",s)

#1-x+x^2-x^3+x^4+ ............x^n
x = int(input("Enter value of x:"))
n=int(input("Enter value of n:"))
s=0
j=1
for i in range(n+1):
j=math.pow(-1,i)
k=math.pow(x,i)
k=k*j
s+=k
print("answer is",s)
x = int(input("Enter the value of x "))
n = int(input("Enter the value of n "))
sum = 0
for i in range(1, n + 1) :
term = x ** i / i
sum += term
print("Sum =", sum)

import math
x = int(input("Enter the value of x "))
sum = 0
m = 1
for i in range(1,x+1) :
term = x ** i / math.factorial(i)
sum += term
print("Sum =", sum)

# Palindrome (12321 is Palindrome)


number=int(input("Enter any number:"))
num=number
num1= number
rev=0
while num>0:
digit=num%10
rev=rev*10+digit
num=int(num/10)
if number==rev:
print(number ,'is a Palindrome')
else:
print(number , 'Not a Palindrome')
# Armstrong number is equal to sum of cubes of each digit
sum = 0
temp = num1
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num1 == sum:
print(num1," is an Armstrong number")
else:
print(num1," is not an Armstrong number")
# Perfect number, a positive integer that is equal to the sum of its proper
divisors.
sum1 = 0
for i in range(1, number):
if(number % i == 0):
sum1 = sum1 + i
if (sum1 == number):
print(number, " The number is a Perfect number")
else:
print(number, " The number is not a Perfect number")

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


if num > 1:
for i in range(2, num):
if (num % i) == 0:
print(num, "is NOT a PRIME number, it is a COMPOSITE number")
break
else:
print(num, "is a PRIME number")
elif num == 0 or 1:
print(num, "is a neither Prime NOR Composite number")
else:
print()

# Create a dictionary with the roll number, name and marks of n students in a class
#and display the names of students who have marks above 75.
n = int(input("Enter the number of students"))
data = {}
for i in range(n):
roll_number = int(input("Enter roll number for student: "))
name = input("Enter name for student: ")
marks = int(input("Enter marks for student: "))
data[roll_number] = {'name': name, 'marks': marks}
print(data)
print("Students who have secured marks above 75")
for roll_number, details in data.items():
if details['marks'] > 75:
print(details['name'])

# list of numbers
list1 = [509, 10, 18, 39, 109, 95]
list1.sort()
print("Smallest element is:", list1[:1])

str = input("Type the string")


vowel=0
consonants=0
uppercase=0
lowercase=0
vowel_list = "aeiouAEIOU"
for alphabet in str:
if alphabet in vowel_list:
vowel=vowel+1
elif alphabet == chr(32):
consonants=consonants
else:
consonants=consonants+1
for elem in str:
if elem.isupper():
uppercase += 1
elif elem.islower():
lowercase += 1
print("Number of UPPER Case in ",str,"' is :",uppercase)
print("Number of lower case in ",str,"' is :",lowercase)
print("Number of Vowels in ",str," is :",vowel)
print("Number of Consonants in ",str," is :",consonants)

# GCD PROGRAM
a = int(input("Enter 1st number: "))
b = int(input("Enter 2nd number: "))
i = 1
while(i <= a and i <= b):
if(a % i == 0 and b % i == 0):
gcd = i
i = i + 1
print("Greatest Common Divisor (GCD) is ", gcd)
# LCM PROGRAM
if a > b:
greater = a
else:
greater = b
while(True):
if((greater % a == 0) and (greater % b == 0)):
lcm = greater
break
greater += 1
print("The Least Common Multiple (LCM) is ", lcm)

You might also like