Ethan's Computer Practicals File 11-B
Ethan's Computer Practicals File 11-B
Code:
message = input("Enter the message: ")
print(message)
Output:
Code:
Output:
Code:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
Output:
Code: Pattern-1
for i in range(0,6):
for j in range(1,i+1):
print("*",end='')
print()
Output:
*
**
***
****
*****
4. Generate the following patterns using nested loops:
Code: Pattern-2
for i in range(5,0,-1):
for j in range(1,i+1):
print(j,end='')
print()
Output:
12345
1234
123
12
1
4. Generate the following patterns using nested loops:
Code: Pattern-3
Alphabets = "ABCDE"
n = len(Alphabets)
for i in range(n):
for a in range(i + 1):
print(Alphabets[a], end='')
print(" ")
Output:
A
AB
ABC
ABCD
ABCDE
5. Write a program to input the value of x and n and print
the sum of the following series:
Code: Series-1
Output:
Enter a value: 1
Enter a value: 1
Therefore the sum of the given series is 2
5. Write a program to input the value of x and n and print
the sum of the following series:
Code: Series-2
total = 0
Output:
Enter a value: 1
Enter a value: 1
Therefore the sum of the given series is 0
6. Determine whether a number is a perfect number, an
Armstrong number or a palindrome.:
Code:
sum = 0
n1 = len(str(n))
temp = n
while temp > 0:
digit = temp % 10
sum += digit ** n1
temp //= 10
if n == sum:
Armstrong=True
else:
Armstrong=False
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
Palindrome=True
else:
Palindrome=False
Code:
if num == 1:
print(num, "is not a prime number")
elif num > 1:
for i in range(2, num):
if (num % i) == 0:
prime=False
break;
if prime:
print(num, "is a prime number")
else:
print(num, "is not a prime number")
Output:
Enter a number: 7
7 is a prime number
8. Display the terms of a Fibonacci series.
Code:
term1 = 0
term2 = 1
print(term1)
print(term2)
Output:
0
1
1
2
3
5
8
13
21
34
9. Compute the greatest common divisor and least common
multiple of two integers
Code:
Output:
Code:
Uppercase = ["A", "B", "C", "D", "E", "F", "G", "H","I", "J", "K",
"L", "M", "N", "O", "P", "Q","R", "S", "T", "U", "V", "W", "X",
"Y", "Z"]
x = str(input("Enter a string: "))
num_vowel=0
num_cons=-1
num_upper=0
num_lower=-1
for i in x:
if i in "aeiouAEIOU":
num_vowel+=1
else:
num_cons+=1
if i in Uppercase:
num_upper+=1
else:
num_lower+=1
Output:
str=input("Enter a string:")
w=""
for element in str[::-1]:
w = w+element
if (str==w):
print(str, 'is a Palindrome string')
else:
print(str,' is NOT a Palindrome string')
Output:
Code:
Output:
Code:
mylist = []
for i in range(5):
value = int(input())
mylist.append(value)
odd_i = []
even_i = []
if i % 2:
even_i.append(mylist[i])
else :
odd_i.append(mylist[i])
Output:
4
7
16
7
9
Code:
mylist = []
for i in range(5):
value = int(input())
mylist.append(value)
element = int(input())
for i in range(5):
if element == mylist[i]:
Output:
Code:
Code:
result = {}
for i in range(no_of_std):
print(result)
Output: