Questions

2 Marks Each

🎯

Test yourself on this topic

25 questions · timed · auto-graded

Question 12 Marks
Write a script to find the roots of a quadratic equation.
Answer
"'A script to find the roots of a quadratic equation."'
View full question & answer
Question 22 Marks
Write a script to input a number. If the number is even, print its square, otherwise print its cube.
Answer
"'A script to input a number. If the number is even, print its square, otherwise print its cube."'
View full question & answer
Question 32 Marks
 Write a script which inputs two numbers from the user and checks if first number is divisible by the second or not. The script should then display an appropriate message.
Answer
"'A script which inputs two numbers from the user and checks if first number is divisible by the second or not.
The script should then display an appropriate message."'
View full question & answer
Question 52 Marks
Write Python script to input a time duration in seconds and display it in the following : ____________ Seconds = _____ hr ________ min _______ seconds. For example, if the user input is 4526, the output should be: 4526 seconds = 1 hr 15 min 26 seconds
Answer
"' Script to Convert Seconds into hours, minute and seconds '''
S =int(input("Enter the Temperature in Celsius"))
print(S," seconds =",end=’ ‘)
H=S//3600
M=S%3600
S =M%60
M=M//60
print(H,"hr",M," min", S, "seconds")
View full question & answer
Question 62 Marks
Write Python script to enter temperature in degree Celsius and display it into Fahrenheit. The formula to convert from degree Celsius to degree Fahrenheit is:
Answer
The formula to convert from degree Celsius to degree Fahrenheit is: ''' Script to Convert Degree Celsius to Fahrenheit '''
C=eval(input("Enter the Temperature in Celsius"))
F=9/5*C+32
print("Temperature in Fahrenheit ", F)
View full question & answer
Question 72 Marks
 Rewrite the above script, but this time to swap the values of variables without using the third variable.
Answer
"'Python script to input two numbers from the user and store these values in two different variables. Then interchange (swap) the values of these two variables without using a third variable."'
a=int(input("Enter the first number"))
b=int(input("Enter the second number"))
a,b=b,a
print("Numbers after the swaps are ",a ," , ",b)
View full question & answer
Question 82 Marks
Write Python script to input two numbers from the user and store these values in two different variables. Then interchange (swap) the values of these two variables using a third variable.
Answer
"'Python script to input two numbers from the user and store these values in two different variables. Then interchange (swap) the values of these two variables without using a third variable."'
a=int(input("Enter the first number"))
b=int(input("Enter the second number"))
temp=a
a=b
b=temp
print("Numbers after the swaps are ",a ," , ",b)
View full question & answer
Question 92 Marks
BMI (Body Mass Index) of a person is used as a screening tool to indicate whether the person is underweight, overweight, obese or a healthy weight for his/her height.
BMI is calculated as follows:
Write Python script to calculate the BMI of a person.
Answer
BMI (Body Mass Index) of a person is used as a screening tool to indicate whether the person is underweight, overweight, obese or a healthy weight for his/her height. BMI is calculated as follows:
''' Program to input the height and weight of a person and calculate his/her BMI.'''
Wt= eval(input(‘Enter weight in Kg: ‘))
Ht = eval(input(‘Enter height in cm: ‘))
Ht /= 100.0 #Convert height into meters
BMI = Wt/(Ht**2)
print (‘Your BMI =’,BMI)
View full question & answer
Question 102 Marks
Write Python script to input the values of Principal, Rate, and Time and calculate Simple Interest and Total Amount.
Answer
"' A python script to input the values of Principal, Rate, and Time and calculate SI and CI."'
P = eval(input(‘Enter Principal: ‘))
R = eval(input(‘Enter rate (% per annum): ‘))
T = eval(input(‘Enter time (in years): ‘))
SI = P*R*T/100
A = P*(1+ R/100.0)**T
CI = A - P
print (‘Simple Interest = Rs’,SI)
print (‘Compound Interest = Rs’,CI)
View full question & answer
Question 112 Marks
Write script to input a number. If the number is negative, then again input the number. Keep on doing so until the user enters a zero or a positive number. When the user enters a non-negative number, display the message "Thank you".
View full question & answer
Question 122 Marks
To display even natural numbers from 2 to n, where n is to be input from the user. For example, if the value of n is 13, the output should be 2 4 6 8 10 12.
Answer
# To display even natural numbers from 2 to n
n = eval(input("Enter the value of n: "))
n=abs(int(n))
for num in range(2, n+1, 2):
print(num)
View full question & answer
Question 132 Marks
To input an integer and find its factorial. Factorial of an integer n (n>=1), is defined as the product of all natural numbers from 1 to n, and is represented by n!. For example, factorial of 5 is represented by 5! and is equal to 1x2x3x4x5 (=120). Factorial of 0 is taken as 1 and factorial of negative integers is not defined.
Answer
# To find the factorial of an integer
n = eval(input("Enter the value of n: "))
n=abs(int(n))
factorial=1
for num in range(2, n+1):
factorial *= num
print(factorial)
View full question & answer
Question 142 Marks
Following is the script to display first n natural numbers, where n is input from the user. If the user enters 0 or a negative number, the code generates no output.
Answer
n = eval(input("Enter a number: "))
for i in range(1,n+1):
View full question & answer
Question 202 Marks
An application (program) is to be developed which offers choices to the user to calculate total surface area and volume of a cylinder, sphere, or cone. The application should input the user's choice and perform the corresponding operation.
View full question & answer
Question 222 Marks
Input principal and time. Then calculate simple interest. If time is more than 10 years, calculate the simple interest at rate of 8% p.a. Otherwise calculate it at rate of 12% p.a.
Answer
"'To input principal and time. Then calculate simple interest. #If time is more than 10 years, calculate the simple interest at rate of 8% #p.a. Otherwise calculate it at rate of 12% p.a.'''
View full question & answer
Question 252 Marks
Write the difference between while loop and for loop
Answer
for Loopwhile Loop
It is used when we know the exact number of iterations.It is used when we know the exact number of iterations.
e.g.
for I in range(1,7):
print(i)
e.g.
while(1):
print("hello")
View full question & answer
2 Marks Each - Computer Science STD 12 Science Questions - Vidyadip