ch
Feedback
CBSE COMPUTER SCIENCE

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
帖子存档
Python code for interfacing with Mysql

ASSIGNMENT SET – 2 Time: 30 min M.M. – 20 Q1. What do you mean by traversing of list in Python? [1] Ans. Traversing means to access each elements of list. This can be done with the help of the loop. Q2. Write the output of the following code: [1] A = [1, 2, 3, 4, 5] print (A[2:6]) Ans. [3, 4, 5] Q3. Elements of list are enclosed in ________ brackets [1] Ans. Square([ ]) Q4. Write an example of nested list. [1] Ans. A = [1, 2, 3, [4, 5]] Q5. Write the output of the following: (if input string is = INDIA) [1] A = list(input(“Enter the String”)) print(A) Ans. [‘I’,’N’,’D’,’I’,’A’] Q6. Which method is used to remove last element of element in list? [1] Ans. pop( ) Q7. Write a program to add only multiples of 3 from the given list. [2] A = [12, 3, 4, 56, 7, 9, 49, 34, 6] Ans. A = [12, 3, 4, 56, 7, 9, 49, 34, 6] s=0 for i in A: if i%3==0: s=s+i print(“Sum of all multiples of 3 is “,s) Q8. Write a function Lavg(list) in python that takes list as argument and display the average of all [2] numbers in the list. Ans. A = [] def Lavg(A): s=0 av=0 for i in A: s=s+i av=s/len(A) print(“Average is “,av) Lavg([1,2,3,4,5,6,7,8,9,10]) #Only to verify the result Q9. Write a function double(list) which takes list as argument and multiply each and every [2] element of list by 2? Ans. A = [] def double(A): for i in range(len(A)): A[i]=A[i]*2 print(“List is “,A) double([1,2,3,4,5]) #Only to verify the result Q10. Write the output of the following code: [2] A = list(“Python List Questions”) for i in range(len(A)-1,0,-5): print(A[i]) Ans. s s t n Q11. Write the output of the following code: [2] a=[‘a’,’b’,’c’] b=a a[0]=’A’ print(a) print(b) Ans. [‘A’, ‘b’, ‘c’] [‘A’, ‘b’, ‘c’] Q12. Write the output of the following code: [4] k = “Subscribe to my blog” L = list(k) 1. print(L[-1:-7:-3]) 2. print(L[:15:-1]) 3. print(L[1:len(k):5]) 4. print(L[2:-15])

ASSIGNMENT SET – 1 Time: 30 min M.M. – 20 Q1. What do you mean by List in Python? [1] Q2. Write the output of the following code: [1] >>> A = [ ] >>> A >>> print(A) Q3. What do you mean by Nested list? Give example [1] Q4. Which method is used to create an empty List? [1] Q5. Negative indexing start from right side of the List(T/F) [1] Q6. Write the code to convert the following string into List. [1] “csiplearninghub” Q7. Write a program to accept 10 numbers from the user and [2] add even numbers in a list named “evenlist” and odd numbers in a list named “oddlist” Q8. Write a function evensum(list) in python that takes list of 10 [2] numbers as argument and display the sum of all even numbers in the list. Q9. What is the difference between slicing and indexing of list? [2] Q10. Write the output of the following code: [2] L = [[1,2],[3,4],[5,6]] print(L[0][0]) print(L[-1]) Q11. Write the output of the following code: [2] [1,3,7,9] < [3,5,4] [‘A’,’b’,’c’] > [‘z’] Q12. Write the output of the following code: [4] S = “csiplearninghub” L = list(S) 1. print(L[-1:-5]) 2. print(L[::-1]) 3. print(L[1:8:2]) 4. print(L[2:5])

Ans: def sum(c): s = 0 for i in range(1, c+1): s=s+i return s print(sum(5)) 12. Rectify the errors in the following statements: 1. Print("Anuj") 2. For i in range(2,4): 3. for i in Range(3,9): 4. def title( ) 5. if i =< 5 Ans: 1. print("Anuj") 2. for i in range(2,4): 3. for i in range(3,9): 4. def title( ): 5. if i <= 5 13. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code N=int(input("Enter any Number:")) S = 0 for i in range(1,N,2) s += 1 if i%2=0: print("i" * 2) else: print("i" * 3) print[S] Ans: N=int(input("Enter any Number:")) S = 0 for i in range(1,N,2): S += 1 if i%2==0: print("i" * 2) else: print("i" * 3) print(S) 14. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. L = [1,2,3,4,5,6,7,'a','e' for i in L: if i==a break: else: print("A") Ans: L = [1,2,3,4,5,6,7,'a','e'] for i in L: if i=='a': break else: print("A") 15. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. a = {'6' : "Amit", '2' : "Sunil" : '3' : "Naina"} for i in a: if int(i)%3=0 print(a(i)) Ans: a = {'6' : "Amit", '2' : "Sunil", '3' : "Naina"} for i in a: if int(i)%3==0: print(a[i])

Python Error Finding Questions 1. Find error(s) in the following code(if any) and rewrite code and underline each correction: x= int(“Enter value of x:”) for in range [0,10]: if x=y print("They are equal") else: Print( "They are unequal") Ans. x= int(input(“Enter value of x:”)) for y in range (0,10): if x==y: print("They are equal") else: print( "They are unequal") 2. Find error(s) in the following code(if any) and rewrite code and underline each correction. a, b = 0 if (a = b) a +b = c print( z) Ans. a= b = 0 if (a == b): c = a + b print( c) 3. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. A = int(input("Enter any number:")) Ar = 0 for x in range(0,A,2) Ar+=x if x%2=0: Print (x*10) Else: print (C) print (Ar) Ans. A = int(input("Enter any number:")) Ar = 0 for x in range(0,A,2): Ar+=x if x%2==0: print (x+2) else: print (x) print (Ar) 4. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. fee=250 0 = i while fee=<2000: if fee<=750: print (fee) fee =+ 250 else: print( "fee"*i) i=i+1 fee=Fee+250 Ans. fee=250 i=0 while fee<=2000: if fee<=750: print (fee) fee += 250 else: print( "fee"*i) i=i+1 fee=fee+250 5. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. 10 = step for e in the range(0 , step): If e%2==0: print(e + 1) else: print(e - 1 Ans. step = 10 for e in range(0 , step): if e%2==0: print(e + 1) else: print(e - 1) 6. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. str = "Welcome to my Blog for S in range[3,9] Print (str(S)) Ans. str = "Welcome to my Blog" for S in range(3,9): print (str[S]) 7. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. For i in Range(10): if(i==5) break: else: print(i) continue Ans: for i in range(10): if(i==5): break else: print(i) continue 8. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. a = input("Enter any number") if a%2=0: print("Even number) Else print("Odd number") Ans. a = int(input("Enter any number")) if a%2==0: print("Even number") else: print("Odd number") 9. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. a = int(Input("Enter any number")) b = int(input("Enter any number")) if a=>b: print("First number is greater")) else: Print("Second number is greater") Ans. a = int(input("Enter any number")) b = int(input("Enter any number")) if a>=b: print("First number is greater") else: print("Second number is greater") 10. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. a = int{input("Enter any number")} for i IN range(1:11): print(a," * " , i , " = ", a*i) Ans. a = int(input("Enter any number")) for i in range(1,11): print(a," * " , i , " = ", a*i) 11. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code def sum(c) s = 0 for i in Range(1, c+1) s=s+i return s print(sum(5)

mysql-connector-python-8.0.13-py3.7-windows-x86-64bit.msi2.99 MB

mysql-connector-python-8.0.13-py3.7-windows-x86-64bit.msi2.99 MB

Download and Install : mysql-installer-community-5.7.33.0

download and install vc_redist.x64 & Windows6.1-KB2999226-x64

mysql.connector for python installation procedure :

Without database name 👆

import mysql.connector as sqltor try: mycon=sqltor.connect(host="localhost",user="root",password="admin",database="test") if mycon.is_connected()==False: print("Error connecting to MYSQL database") else: print(mycon.is_connected()) mycon.close() except: print("Exception Raised")

with database name👆

import mysql.connector as sqltor try: mycon=sqltor.connect(host="localhost",user="root",password="admin",database="test") if mycon.is_connected()==False: print("Error connecting to MYSQL database") else: print(mycon.is_connected()) mycon.close() except: print("Exception Raised")

Python interface with MySQL connection testing program..

https://t.me/boardclass12 👈 CBSE CLASS 12 NOTES

Share this link to your classmates also... https://t.me/cbsecomputerscience

ANNUAL REVISION-3-MAT-CS-QSET-ANS.docx0.71 KB

Data_file_handling_in_python_class_12_Objective_type_questions.pdf4.68 KB

SAMPLE QP-2021-2.pdf9.41 KB