GUVI
Back

[SOLVED] All Python questions solved.

Created 3 years ago
81501 Views
17 Comments
AnjaneySingh
@AnjaneySingh
AnjaneySingh
@AnjaneySinghProfile is locked. Login

This is the solution of the python course you get after enrolling for Master Python and make a face Recognition App.

Please Note: On completing this course, You will not get the certificate for free, they'll charge you.

GUVI PYTHON:

xxxxxxxxxxxxxxxxxxxxxxxx

BEGINNER MODULE: 

xxxxxxxxxxxxxxxxxxxxxxxx

  1. This course is for anyone who is even in their starting stages of programming (True)

  2. What is the first topic we will be covering? (Why python)

  3. What is the expected excitement level from you? (100,000!!!!)

  4. Who is the creator of Python? (Guido Van Rossum)

  5. When was Python created? (1991)

  6. Python can work on different platforms as well? (True)

  7. What can we write to check what version of Python is running on our system in the Windows Command Prompt? (py)

  8. What is the other option besides writing "py" to check the version in the Windows CMD? (python - - version)

  9. What is the full form of IDE? (Integrated Development Environment)

  10. An IDE consists of all the necessary Development tools that a programmer needs in one place. ( True )

  11. What is used to get an output in Python ( print(“ ”) )

  12. Write the correct input : ______("Hello World") (print)

  13. What is the correct syntax from the following ( print(“Hello”))

  14. Insert the correct syntax to convert x into a floating point number. x=10 x= ______(x) ( float )

  15. Insert the correct syntax to convert x into a integer. x = 5.5 x = _________(x) (int)

  16. Divide 10 by 2, and print the result print(10 __ 2) ( / )

  17. What is the error when you enter the wrong name of a module? ( ModuleNotFound Error)

  18. What error can we expect from the following: from math import cube ( Import Error )

  19. What error can we expect from the following: it= iter([1,2,3]) next(it) next(it) next(it) next(it) ( StopIteration )

ASSIGNMENT 1:

  1. Write a code to print a statement "Hello,Darkness"

code: 

print("Hello,Darkness")

  1. Declare 10 variables and perform arithmetic operations(Addition,Multiplication,Division) on them.

code: 

int a,b,c,d,e,f,g,h,i,j= 10,9,8,7,6,5,4,3,2,1

Addition = a+b+c

Multiplication = def*g

Division = h/i

print("ADDITION: ",Addition)

print("MULTIPLICATION: ",Multiplication)

print("DIVISION: ",Division) 

  1. Declare 10 variables and perform arithmetic operations(Exponential, Modulus and Floor Division) on them.

code: 

int a,b,c,d,e,f,g,h,i,j= 10,9,8,7,6,5,4,3,2,1

Addition = a+b+c

Multiplication = def*g

Division = h//i

print("ADDITION: ",Addition)

print("MULTIPLICATION: ",Multiplication)

print("DIVISION: ",Division)


xxxxxxxxxxxxxxxxxxxxxxxx

INTERMEDIATE MODULE

xxxxxxxxxxxxxxxxxxxxxxxx

  1. Create a variable named bike and assign the value Kawasaki H2R to it ( bike = “Kawasaki H2R” )

  2. Create a variable named x and assign the value of integer 50 to it ( x=50 )

  3. Display the sum of 5 + 10, using two variables: x and y ( x=10 y=5 print(x+y) )

  4. Select the illegal variable name ( 2my-first_name = “John” )

  5. What is used to print the length of a string ( len() )

What can we use to get the first character of a string txt= "Banana" ( x= txt[0] )

  1. What can we use to get the characters from index 2 to index 4 (llo) in txt = "Hello, World" ( x= txt [2:5] )

  2. Select the right syntax for the if condition ( a=10 b = 20 if a>b: print(“Hello World”) )

  3. Fill in the blank if a> b: print("True") _____: print("False") ( else: )

  4. What will be the output for the following program: a = 50 b = 10 if a == b: print("1") elif a > b : print("2") else: print("3") ( 2 )

  5. Select the right syntax to create a function called my_function ( def my_function: )

  6. Inside a function with two parameters, print the first parameter. def myfunction(fname, lname): print(_______) ( fname)

  7. What will be the output of the following code when x=20 : def my_function(x): return x + 5 print(x) ( 20 )

  8. What will be the output of the following program: fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": print(x). ( banana )

  9.   The following code will stop the loop if i is 3 Fill in the blanks to perform the same i = 1 ______ i < 6: if i == 3: break i += 1 ( while )

  10. What will be the output for the following code: for x in range(6): print(x) ( 0 1 2 3 4 5 )

ASSIGNMENT 2:

  1. Print the length of the string 'programmer'

code:

print(len("programmer"))

  1. Print the following string by using escape characters : We are "VIKINGS" of the north

code: 

print("We are \"Vikings\" of the north.")

  1. Write a code to loop through a list of numbers and print it

code:

num=[1,2,3,4,5]

for i in num:

print(i)

xxxxxxxxxxxxxxxxxxxxxxxx

ADVANCED MODULE:

xxxxxxxxxxxxxxxxxxxxxxxx

  1. What is the output of the following code: def myfunction(fname, lname): print(lname + " " + fname) myfunction("Coco", "Sheth") ( Sheth Coco )

  2. What is the correct output for: def myfunction(food): for x in food: print(x) fruits = ["apple", "banana", "cherry"] myfunction(fruits) ( apple banana cherry )

  3. Output for the following: def myfunction(x): return 5 * x print(myfunction(3)) print(myfunction(5)) print(myfunction(9)) ( 15 25 45 )

  4. What will be in the blank space to print the second item: fruits = ["apple", "banana", "cherry"] print(______) ( fruits[1] )

  5. What do we use to add something to a list ( append() )

  6. Fill in the blank to use a range of indexes to print the third, fourth, and fifth item in the list fruits = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(fruits[__]) ( 2:5 )

  7. What do we use to remove banana from the list: lsi = ["apple", "banana", "cherry"] ( lsi.remove(“banana” ) )

  8. Use the correct syntax to print the first item in the fruits tuple. fruits = ("apple", "banana", "cherry") print(fruits[__]) ( 0 )

  9. Use the correct syntax to print the number of items in the fruits tuple. fruits = ("apple", "banana", "cherry") ( print(len(fruits)) )

  10. Use negative indexing to print the last item in the tuple. fruits = ("apple", "banana", "cherry") print(fruits[___])  ( -1 )

  11. How can we print the value of the "model" key of the car dictionary. car = { "brand": "Ford", "model": "Mustang", "year": 1964 } ( print(car.get(“model”)) )

  12. What can we do to change the value of the year from 1964 to 2020: car = { "brand": "Ford", "model": "Mustang", "year": 1964 } ( car[“year”]=2020 )

  13.   What can we use to remove something from a dictionary ( pop() )

  14. What is the output of the following code: fruits = ["apple", "banana", "cherry", "kiwi", "mango"] newlist = [x for x in fruits if "a" in x] print(newlist) (  [‘apple’ , ‘banana’ , ‘mango’ ] )

  15. What is the output of the following code: fruits = ["apple", "banana", "cherry", "kiwi", "mango"] newlist = [x for x in fruits] print(newlist) ( [‘apple’ , ’banana’ , ‘cherry’ , ‘kiwi’ , ‘mango’ ] )

  16. What is the output of the following code: newlist = [x for x in range(10) if x < 5] print(newlist) ( 0 1 2 3 4 )

  17. Which of the following is used to open a file for reading? ( “r” )

  18. Which of the following is used to add data to the end of the file? ( “a” )

  19. Which of the following is the right syntax to open a file for reading. ( f= open(demofile.txt) )

  20. A breakpoint is a to permanently suspend execution of your program at a certain point ( False )

  21. Breakpoints provide a tool that enables you to suspend execution where and when you need ( True )

  22. You can set break points on as many lines as you want ( True )

  23. What does the variables tab show ( values of variable )

  24. What will be the output for the following code: class Person: def init(self, name, age): self.name = name self.age = age p1 = Person("John", 36) print(p1.name) print(p1.age) ( John 36 )

  25. Fill in the blanks: class Person: def ______(self, name, age): self.name = name self.age = age ( - - init - - )

  26. What will be the output of the following code: class MyClass: x = 5 ** 10 p1 = MyClass() print(p1.x) ( 9765625 )


ASSIGNMENT 3:


  1. Write a code using a function to check whether a given number is even or odd

code: 

def check(n):

if n%2==0:

    return "Even"

    else:

    return "Odd”     

print(check(5))

 

  1. Write a code using a function to check whether a given number is prime number or not

code:

def prime(n):

flag=0

if n<=1:

    return "Non_Prime"

    if n<=3:

    return "Prime"

    if (n % 2 == 0 or n % 3 == 0) :

        return "Non_Prime"

    i=5

    while(i * i <= n) :

        if (n % i == 0 or n % (i + 2) == 0) :

            return "Non_Prime"

        i = i + 6

    return "Prime"

print(prime(8))


  1. Write a code to print a Fibonacci series upto the nth term. Use the int(input()) to get an input from the user as well for the value of n.)

code: 

def fib(n):

    if n<=0:

        print("Enter positive number")

    if n==1:

        print("0")

    else:

        a,b=0,1

        x=0

        count=0

        while(count<n):

            print(a,end=" ")

            x=a+b

            a,b=b,x

            count+=1

n=int(input())

fib(n)


xxxxxxxxxxxxxxxxxxxxxxxx

EXPERT MODULE: 

 xxxxxxxxxxxxxxxxxxxxxxxx

  1. Lambda is an ( Anonyms Module )

  2. Lambdas are defined using def ( False )

  3. What will be the output of the following code: def fun(variable): letters = ['a', 'e', 'i', 'o', 'u'] if (variable in letters): return True else: return False sequence = ['g', 'e', 'e', 'j', 'k', 's', 'p', 'r'] filtered = filter(fun, sequence) print('The filtered letters are:') for s in filtered: print(s) ( e e )

  4. What is the code to install a new package ( pip install )

  5. Which of the following will show you all the packages that are present ( pip list )

  6. What is the CMD code to upgrade our pip ( pip install - - upgrade pip )

  7. What is the index position for the first sheet ( 0 )

  8. What will be in the blank to print cell A3 import xlrd loc = ("path of file") wb = xlrd.openworkbook(loc) sheet = wb.sheetbyindex(0) print(sheet.cellvalue(__ , __)) ( 2,0 )

  9. What does using nrows do ( Give the the number of Rows )

  10. What module do we use to connect to MySQL ( mysql.connector

  11. What does the mydb.cursor() do ( you can create a cursor object )

Which one of the following function is used to execute an SQL query ( execute(query) )

  1. Which one of the following function gets all the values of a selected table ( fetchall() )

  2. __________ is a general term for taking each item of something, one after another ( Iterator )

  3. An iterable is an object that has an _______ method ( iter )

  4. Whenever you use a For loop, or map, or a list comprehension, etc. in Python, the ____ method is used. ( next() )

  5. In object-oriented programming, _______________ is the process of transforming data structures or objects into a format that can be offloaded to a file, memory cache or transmitted over the network connection and the same object can be reconstructed later in the same or different environment. ( Serialisation )

  6. Serialization is converting the object into the stream of bytes also called _______ an object, and the reverse process of rebuilding the object back from the stream of bytes is deserialization or _________. ( storing , restoring )

  7. What happens to the data stored in the txt file using pickle.dump ( Data is stored as bytes

  8. ____________ is the Creator or Father of JSON. ( Douglas Crockford )

  9. How to prettyprint a JSON file in Python? ( json.dumps(parsed, indent=4 , sort_keys = True ) )

  10. JSON Objects begins and ends with __ and ___. ( { and } )


xxxxxxxxxxxxxxxxxxxxxxxx

FINAL PROJECTS:

xxxxxxxxxxxxxxxxxxxxxxxx

  1. Get a list of name as an input from the user and make the first letters in caps and print each word as a list

code:

n= list(map(int,input().split(',')))

for i in n:

print(i.capitalize())



  1. Get a list of name as an input from the user and make the first letters in caps and print each word as a list

code:


import mysql.connector

mydb = mysql.connector.connect(

  host="localhost",

  user="demo",

  password="worldsbestpassword",

  database="mydb"

)

mycursor = mydb.cursor()

s = "INSERT INTO demo (demoname, demoaddress) VALUES (%s, %s)"

v = ("Minions", "Minion_City")

mycursor.execute(s, v)

mydb.commit()


  1. Write a Python code to reverse the given integer and print the integer

code: 

s=str(input())

print(int(s[::-1]))


  1. Write a Python code to read an integer in a file e.g 123 and convert it to words e.g One hundred and twenty three and write the result back to the same file such that your file will have "123 One hundred and twenty three " in it

code:

def Words(n): 

    units = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"] 

    teens = ["Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"] 

    tens = ["Twenty","Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"] 

    if n <=9: 

        return units[n] 

    elif n >= 10 and n <= 19: 

        return teens[n-10] 

    elif n >= 20 and n <= 99: 

        return tens[(n//10)-2] + " " + (units[n % 10] if n % 10 !=0 else "") 

    elif n >= 100 and n <= 999: 

        return Words(n//100) + " Hundred " + (Words(n % 100) if n % 100 !=0 else "") 

    elif n >= 1000 and n <= 99999: 

        return Words(n//1000) + " Thousand " + (Words(n % 1000) if n % 1000 !=0 else "") 

    elif n >= 100000 and n <= 9999999: 

        return Words(n//100000) + " Lakh " + (Words(n % 100000) if n % 100000 !=0 else "") 

    elif n >= 10000000: 

        return Words(n//10000000) + " Crore " + (Words(n % 10000000) if n % 10000000 !=0 else "")


text = open("num.txt","r")

conv= Words(text)

file1 = open("num.txt", "a")

file1.write(conv)


Comments (17)
Please login to comment.
 
Powered by habitate.io Habitate