0% found this document useful (0 votes)
41 views9 pages

Cs Record

Uploaded by

paariarjun7
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)
41 views9 pages

Cs Record

Uploaded by

paariarjun7
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/ 9

Input1:

mssg=input("enter a welcome message")


print("hello",mssg)

output1:

enter a welcome messagehow are you


hello how are you

input2:

#input first num


num1=int(input("enter the first number"))
#input the second num
num2=int(input("enter the second number"))
#check if first number is greater than second
if (num1>num2):
print("the larger number is",num1)
else:
print("the larger number is",num2)

output2:

enter the first number6


enter the second number3
the larger number is 6

input3:

#input first,second,third num


num1=int(input("enter the first number"))
num2=int(input("enter the second number"))
num3=int(input("enter the third number"))
#check if first number is greater than the rest of the two numbers
if (num1>num2 and num1>num3):
print("the larger number is",num1)
#check if second number is greater than the rest of the two numbers
elif(num2>num1 and num2>num3):
print("the larger number is",num2)
else:
print("the larger number is",num3)

output3:

enter the first number7


enter the second number5
enter the third number6
the larger number is 7

input4:

row=int(input("enter numbers of rows:"))


#if you want user to enter a number,uncomment the below line
#row=int(input("enter numbers of rows:"))
#outer loop
for i in range(row):
#nested loop
for j in range(i):
#display number
print(i,end='')
#new line after each row
print('')

output4:

enter numbers of rows:6

1
22
333
4444
55555

input5:

row=int(input("enter numbers of rows:"))


for i in range(1,row+1):
for j in range(1,i+1):
print(j,end='')
print('')

output5:

enter numbers of rows:6


1
12
123
1234
12345
12345

input6:

row=int(input("enter numbers of rows:"))


for i in range(0,row):
for j in range(0,i+1):
print("*",end='')
print("\r")

output6:

enter numbers of rows:5


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

input7:

def series_sum(x, n):


total = 1.0
multi = x
#first term
print(1, end=" ")

# Loop to print the N terms


#of the series and find their sum
for i in range(1, n):
total += multi
print(f'+ {multi:.1f}', end=" ")
multi *= x

print('\n')
return total

# Driver code
x = 2
n = 5
print(f'The sum of the series is: {series_sum(x, n):.2f}')

output7:

1 + 2.0 + 4.0 + 8.0 + 16.0

The sum of the series is: 31.00

input8:

n=int(input("enter any number:"))


sum1=0
for i in range(1,n):
if(n%i==0):
sum1=sum1+i
if(sum1==n):
print("the number is a perfect number:")
else:
print("the number is not a perfect number!")

output8:

enter any number:6


the number is a perfect number:

input9:

num=int(input("enter a number:"))
#changed num variable to string
# and calculate the length(number of digits)
order=len(str(num))
#initialize sum
sum=0
#find the sum of the cube of each digit
temp=num
while temp>0:
digit=temp%10
sum+=digit**order
temp//=10
#display the result
if num==sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")

output9:

enter a number:153
153 is an Armstrong number

input10:

num=int(input("enter a number"))
temp=num
reverse=0
while temp>0:
remainder=temp%10
reverse=(reverse*10)+remainder
temp=temp//10
if num==reverse:
print('Palindrome')
else:
print("not Palindrome")

output10:

enter a number12
not Palindrome

input11:

num=int(input("enter a number:"))
#if given number is greater than 1
if num>1:
#iterate from2 to n/2
for i in range(2,int(num/2)+1):
#if num is divisible by any number
#2 and n/2,it is not a prime number
if(num%i)==0:
print(num,"is not a prime number")
break
else:
print(num,"is a prime number ")
else:
print(num,"is not a prime number")

output11:

enter a number:7
7 is a prime number

input12:

num=int(input("enter a number:"))
n=0

for i in range(1,num+1):
if num%i==0:
n+=1
if n>2:
print("the number is composite")
else:
print("sorry,your number is prime")

output12:

enter a number:9
the number is composite
input13:

#python program to generate fibonacci series based on n value


n=int(input("enter a number"))
a=0
b=1
sum=a+b
count=1
print("fibonacci series is:",end="")
while(count<=n):
count+=1
print(a,end=" ")
a=b
b=sum
sum=a+b

output13:

enter a number10
fibonacci series is:0 1 1 2 3 5 8 13 21 34

input14:

num1=int(input("enter a number:"))
num2=int(input("enter a number:"))
gcd=1

for i in range(1,min(num1,num2)):
if num1%i==0 and num2%i==0:
gcd=1
print("GCD of",num1,"and",num2,"is",gcd)

output14:

enter a number:4
enter a number:7
GCD of 4 and 7 is 1

input15:

num1=int(input("enter a number:"))
num2=int(input("enter a number:"))
for i in range(max(num1,num2),1+(num1*num2)):
if i %num1==i%num2==0:
lcm=i
break
print("LCM of",num1,"and",num2,"is",lcm)

output15:
enter a number:4
enter a number:6
LCM of 4 and 6 is 12

input16:

str=input("type the string:")


vowel_counts=0
consonants_counts=0
uppercase_counts=0
lowercase_counts=0

vowel=set("aeiouAEIOU")

for alphabet in str:


if alphabet in vowel:
vowel_counts+=1
elif alphabet.isalpha():
consonants_counts+=1

for elem in str:


if elem.isupper():
uppercase_counts+=1
elif elem.islower():
lowercase_counts+=1

print("Number of Vowels in str",str,"is:",vowel_counts)


print("Number of consonants in str",str,"is:",consonants_counts)
print("Number of UPPER case in str",str,"is:",uppercase_counts)
print("Number of LOWER in str",str,"is:",lowercase_counts)

output16:

type the string:Hi Team,Welcome


Number of Vowels in str Hi Team,Welcome is: 6
Number of consonants in str Hi Team,Welcome is: 7
Number of UPPER case in str Hi Team,Welcome is: 3
Number of LOWER in str Hi Team,Welcome is: 10
input17:

#enterr input string


string=input("enter string:")
#declare an empty tring variable
revstr=""
#iterate string with for loop
for i in string:
revstr=i+revstr
print("reversed string:",revstr)
if(string==revstr):
print("the string is a palindrome")
else:
print("the string is not a palindrome")

output17:

enter string:malayalam
reversed string: m
reversed string: am
reversed string: lam
reversed string: alam
reversed string: yalam
reversed string: ayalam
reversed string: layalam
reversed string: alayalam
reversed string: malayalam
the string is a palindrome

You might also like