CBSE COMPUTER SCIENCE
Ir al canal en 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
Mostrar más549
Suscriptores
Sin datos24 horas
Sin datos7 días
Sin datos30 días
Archivo de publicaciones
# define functions
def add(x, y):
"""This function adds two numbers"""
return x + y
def subtract(x, y):
"""This function subtracts two numbers"""
return x - y
def multiply(x, y):
"""This function multiplies two numbers"""
return x * y
def divide(x, y):
"""This function multiplies two numbers"""
return x / y
def floordiv(x, y):
"""This function multiplies two numbers"""
return x // y
def moddiv(x, y):
"""This function multiplies two numbers"""
return x % y
# take input from the user
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
print("5.Floor Division")
print("6.Modulo Division")
choice = input("Enter choice(1/2/3/4/5/6):")
while choice<'7':
num1 = int(input("Enter first number: "))
num2 = int(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 = input("Enter choice(1/2/3/4/5/6):")
print("Exited")
def fibo(n):
if n <= 1:
return n
else:
return(fibo(n-1) + fibo(n-2))
# take input from the user
num = int(input("How many terms? "))
# check if the number of terms is valid
if num <= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
for i in range(num):
print(fibo(i))
term =fibo(num-1)
print("Nth term of this series is : ",term)
# 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))
#To find sum of elements of list recursively
def findSum(lst,num):
if num==0:
return 0
else:
return lst[num-1]+findSum(lst,num-1)
mylist = [] # Empty List
#Loop to input in list
num = int(input("Enter how many number :"))
for i in range(num):
n = int(input("Enter Element "+str(i+1)+":"))
mylist.append(n) #Adding number to list
sum = findSum(mylist,len(mylist))
print("Sum of List items ",mylist, " is :",sum)
#To check the given number is Prime or Not
import math
num = int(input("Enter any number :"))
isPrime=True
for i in range(2,int(math.sqrt(num))+1):
if num % i == 0:
isPrime=False
if isPrime:
print("## Number is Prime ##")
else:
print("## Number is not Prime ##")
# To calculate factorial of a given number
def fact(n):
if n > 1:
return n*fact(n-1)
else:
return n
num = int(input("Enter any number :"))
print("Factorial of ", num , " is :",fact(num))
# To calculate factorial of a given number
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)
https://www.qb365.in/materials/stateboard/12th-computer-science-python-and-csv-files-book-back-questions-3927.html
Online Test : https://www.qb365.in/materials/online-test/148380/python-and-csv-files-practice-test-1.html
https://www.tutorialaicsip.com/cs-xii-qna/file-handling-in-python-class-12/
https://www.techbeamers.com/python-file-handling-quiz-part-2-experienced/
https://www.cbsetuts.com/important-questions-class-12-computer-science-python/
https://www.w3resource.com/python-exercises/file/
I want to get input from the user and it will give sorted order then what will be changee by you in the above program?
[42, 29, 74, 11, 65, 58]
0 , 0 n-i-1 5 [29, 42, 74, 11, 65, 58]
0 , 1 n-i-1 5 [29, 42, 74, 11, 65, 58]
0 , 2 n-i-1 5 [29, 42, 11, 74, 65, 58]
0 , 3 n-i-1 5 [29, 42, 11, 65, 74, 58]
0 , 4 n-i-1 5 [29, 42, 11, 65, 58, 74]
1 , 0 n-i-1 4 [29, 42, 11, 65, 58, 74]
1 , 1 n-i-1 4 [29, 11, 42, 65, 58, 74]
1 , 2 n-i-1 4 [29, 11, 42, 65, 58, 74]
1 , 3 n-i-1 4 [29, 11, 42, 58, 65, 74]
2 , 0 n-i-1 3 [11, 29, 42, 58, 65, 74]
2 , 1 n-i-1 3 [11, 29, 42, 58, 65, 74]
2 , 2 n-i-1 3 [11, 29, 42, 58, 65, 74]
3 , 0 n-i-1 2 [11, 29, 42, 58, 65, 74]
3 , 1 n-i-1 2 [11, 29, 42, 58, 65, 74]
4 , 0 n-i-1 1 [11, 29, 42, 58, 65, 74]
>>>
l=[42,29,74,11,65,58]
n=len(l)
print(l)
for i in range(n-1):
for j in range(n-i-1):
if l[j]>l[j+1]:
l[j],l[j+1]=l[j+1],l[j]
print(i,',',j,'n-i-1',n-i-1,' ',l)
print()
