HomeCHAPTER CLASS 12 Revision Tour - 1 Sumita Arora Practical Class 12 Computer science 2 Comments Facebook Twitter Revision Tour - 1 Sumita Arora Practical Class 12 Computer Science SolutionP.P.I : - 1.1Q1. For each of the following, write a single (that is, one) Python statement:(a) Tell the user to Enter your name, then read in, and assign to a variable, a string typed in by the user.(b) Tell the user to Enter your age, then read in, and assign to a variable, an integer typed in by the user.(c) Print out, on separate lines, Your name is name and Your age is age, where name and age are the values of the two variables entered above.Q2. Give three examples of legal variable names and two examples of illegal variable names in Python. For the illegal variable names explain why they are illegal. Do not use one-letter variable names.Legal Names(i)(ii)(iii)Illegal Names(i)(ii)Q3. In each of the following parts there is an error in the Python code. Identify the error by name and describe the problem. (Each piece of code is prefixed with a brief description of the programmer's intention.)(i) The following code attempts to compute the product of m and x added to b and assign that value to y.y = mx + b(ii) The following code attempts to compute the first-order effects of some physical process. You may assume that equation is correct.cofactor = alpha * x * x1storder = 1.0 / cofactor2ndorder = 2.0 ** 1storderQ4. While taking input from input(), you need to convert the input into float and int types, if you are reading numbers.(a) What built-in function do you use to convert a string into a floating-point number? Demonstrate this function by converting string '85' into a floating-point number and assigning it to a variable x.(b) What built-in function do you use to convert a string into an integer?(c) What happens when you try to convert a string into an integer but the string is not a number?Q5. What would be the output of following code?print ('doesn\'t')print ("doesn\'t")print (" "Yes," he said.")print ("\"Yes, \" he said.")Q6. Write a program to print an acrostic poem as shown below:-These things I have sPoken unto you, that in me yE might have peace. In the world ye shAll have tribulation : but be good Cheer ; I have overcomE the worldIn the output you need not print bigger letter for P E A C E, but make sure these letters make a vertical word in the output.Q7. Write a program to print following ASCII art using print statements:-(a) (b) P.I.P :- 1.2Q1. In each of the following Python expressions or statements, indicate what data type belongs in the indicated place by choosing one of these data types:int, float, bool, str, list Expression Correct Datatype(a) s = ____ + 17 (b) t = ____ + “pie” (c) x [____] = ‘catfood’ (d) ____ .sort() (e) if ____ : Q2. What does Python print as it executes the following sequence of statements? Expression Correct Datatype(a) print ((10+3)*2) (b) print (11/2) (c) x = 25print (x * 2 == 50) (d) print (x /2 >= 50) (e) a = ‘Honda'b="Audi'print (a + b) (f) c = len (a) + len (b)print (c) (g) print (a) (h) print (a[1]) Q3. What would be the output of following code?a = 9000 # initializes and assigns value to variableprint ("Now it's a", type(a))a = float(a)print ("Now it's a", type(a))a = str(a)print("Now it's a", type(a))Q4. What would be the output of following code? Support your answer with reasons.x = 4y = 8z = x / y * yprint(z)Q5. Which of the following statements would yield 2? Assume that math module is imported. Recall that math.fabs() gives you absolute value of its argument.(a) print(5/2)(b) print(5.0//2)(c) print((int) ( 5 //2))(d) print(math.fabs (-5.0 / 2))(e) print(math.fabs ( -5 // 2))(f) print(math.fabs(-3//2))(g) print(-5/2)(h) print(-5/2)(i) print (-5//2)(j) print(-5.0//2)Q6. Which of the following statements would yield 2.0? Assume that math module is imported. Recall that math.fabs() gives you absolute value of its argument.(a) print(5/2)(b) print(5.0//2)(c) print((int)(5.0//2))(d) print(math.fabs(-5.0/2))(e) print(math.fabs(-5.0//2))(f) print (math.fabs(-3//2))(g) print(-5/2)(h) print(-5/2)(i) print(-5//2)(j) print(-5.0//2)Q7. What would be the output produced by the print statements given below?import math(a) print(5/2)(b) print(5.0//2)(c) print((int) ( 5 //2))(d) print(math.fabs (-5.0 / 2))(e) print(math.fabs ( -5 // 2))(f) print(math.fabs(-3//2))(g) print(-5/2)(h) print(-5/2)(i) print (-5//2)(j) print(-5.0//2)Q8. What would be the output of the following?(a) print(type([1,2]))(b) print(type(1,2))(c) print(type((1,2)))(d) print(type(1/2))(e) print(type([1/2]))(f) print(type((1/2)))(g) print(type((1/2,)))Q9. What would be the output of the following?x = Truey = Falsez = Falseprint(x or y and z)Q10. Given the following Boolean variables, what would be the output of the following statements?x = Truey = Falsez = False(a) print(not x or y)(b) print(not x or not y and z)(c) print(not x or y or not y and x)(d) print('ant' < 'amoeba')Q11. Write a program to find the side of square whose you read from user.Q12. Write a program to calculate the distance of 1056 feet in term of yards and mile.Q13. An athlete is taking rounds of a triangular park with sides as 30 m , 25 m and 35 m . the athlete has 560 m till now .write a program to print how many rounds of park the athlete has completed.Q14. Write a program that calculate and prints on the screen the number of seconds in a year.P.I.P :- 1.3Q1. What is the output of the following python program? First try and predict the output without the computer. Check your answer by typing it in and running it.i = 0while i < 6: j = 0 while j < i: print("*", end = '') j = j + 1 i = i + 1 print()Q2. What is the output of the following program ?x = 7y = 8if x < 7 or x <= 10 and y > 8 : print("IT IS!")else: print("Oh No")Q3. What is the output of the program?score = 40while score > 1: score = score/2 - 1 print(score, end = '')Q4. Consider the following code:x = int (input ("Enter the value of 'x' :- "))if x > 3: if x <= 5: y = 1 elif x != 6: y = 2 else: y = 3else: y = 4If y has the value 2 after executing the above program fragment, then what do you know about the initial value of x?Q5. Consider the following two fragments:if x == 5 : x = x + 1else: x = 8if x ==5: x = x + 1if x != 5: x = 8Are the two fragments logically equivalent? Why or why not?Q6. Write a program that print a table on two column: on the left the integer temperatures between 0 and 100 (Fahrenheit) and in the right column the corresponding Celsius values.Q7. Write a program to print the following pattern:-******** * * * * ********* Q8. Write program that generate each of the patterns given below:-******************************************************* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *************** ******* ***** *** ** *** ***** ******* **************
Kindly provide your phone number. Or call me at 7897254607
ReplyDeletePlease chat me on telegram.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )