CBSE COMPUTER SCIENCE
前往频道在 Telegram
QUESTION BANK, REFERENCE BOOK, LAB MANUAL , WORKSHEET ETC., PYTHON TEXT BOOK AND REFERENCE BOOKS, 01. ASK QUESTIONS AT https://t.me/joinchat/FJ1noGs-64I0OWI1
显示更多549
订阅者
无数据24 小时
无数据7 天
无数据30 天
帖子存档
Dear Student.. Prepare well about your projects that is whatever module in it .. what is the function of each module.... explain about each module.. and individual statements ...
# To calculate factorial of a given number using Iteration
num = int(input("Enter any number :"))
fact = 1
n = num # storing num in n for printing
while num>1: # loop to iterate from n to 2
fact = fact * num
num-=1
print("Factorial of ", n , " is :",fact)
#To check the given number is Prime or Not
num = int(input("Enter any number :"))
PRIME=True
for i in range(2,num+1):
if num % i == 0:
PRIME=False
if PRIME:
print("The given Number is Prime")
else:
print("The given Number is not Prime")
# To find Fibonacci series : 0,1,1,2,3,5,8,13,... as a LIST Object
def fibo(num):
a=0
b=1
fib=[a,b]
for i in range(3,num+1):
c=a+b
fib.append(c)
a=b
b=c
return fib
num = int(input("How many terms? "))
print("Fibonacci Series : ",fibo(num))
# define functions
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
def floordiv(x, y):
return x // y
def moddiv(x, y):
return x % y
# USER OPTIONS
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
print("5.Floor Division")
print("6.Modulo Division")
choice = int(input("Enter choice(1/2/3/4/5/6):"))
while choice<7:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice==1:
print(num1,"+",num2,"=", add(num1,num2))
elif choice==2:
print(num1,"-",num2,"=", subtract(num1,num2))
elif choice==3:
print(num1,"*",num2,"=", multiply(num1,num2))
elif choice==4:
print(num1,"/",num2,"=", divide(num1,num2))
elif choice==5:
print(num1,"//",num2,"=",floordiv(num1,num2))
elif choice==6:
print(num1,"%",num2,"=",moddiv(num1,num2))
choice = int(input("Enter choice(1/2/3/4/5/6):"))
else:
print("Invalid Choice")
print("Exited")
#Program to read content of file line by line
#and display each word separated by '#'
f = open("file.txt")
line=f.readline()
for x in line:
words = line.split()
for w in words:
print(w+'#',end='')
print()
line=f.readline()
f.close()
#Program to read content of file
#and display total number of vowels, consonants, lowercase and uppercase characters
f = open("file.txt")
v=0 #Vowels counting
c=0 #Consonants counting
u=0 #Uppercase counting
l=0 #Lowercase counting
o=0 #Others counting
data = f.read()
vowels=['a','e','i','o','u','A','E','I','O','U']
for ch in data:
if ch.isalpha():
if ch in vowels:
v+=1
else:
c+=1
if ch.isupper():
u+=1
elif ch.islower():
l+=1
else:
o+=1
print("Total Vowels in file :",v)
print("Total Consonants in file n :",c)
print("Total Capital letters in file :",u)
print("Total Small letters in file :",l)
print("Total Other than letters :",o)
f.close()
#Program to read line from file and write it to another line
#Except for those line which contains letter “a”
f1 = open("FILE.TXT")
f2 = open("FILE1.TXT","w")
x=f1.readlines()
for line in x:
if 'a' not in line:
f2.write(line)
print("## File Copied Successfully! ##")
f1.close()
f2.close()
