Exercise: Console Io
Questions for: Console Io
How can you prompt the user to enter two numbers and print their product?
A:
product = input("Enter first number: ") * input("Enter second number: "); print(product)
B:
product = int(input("Enter first number: ")) * int(input("Enter second number: ")); print(product)
C:
product = multiply_numbers(input("Enter first number: "), input("Enter second number: ")); print(product)
D:
product = input("Enter first number: ").multiply(input("Enter second number: ")); print(product)
Answer: B
To prompt the user to enter two numbers and print their product, use
int(input("Enter first number: ")) * int(input("Enter second number: ")); print(product).
How can you read a password from the console and check if it meets certain criteria?
A:
password = input("Enter password: "); validate_password(password)
B:
password = input_password(); check_password_criteria(password)
C:
password = getpass.getpass("Enter password: "); is_valid_password(password)
D:
password = input("Enter password: "); validate_password_criteria(password)
Answer: A
To read a password from the console and check if it meets certain criteria, use
input("Enter password: "); validate_password(password).Discuss About this Question.
How can you print the sum of all odd numbers from 1 to 10?
A:
print(sum(range(1, 11, 2)))
B:
odd_sum(1, 10)
C:
print(odd_numbers_sum(1, 10))
D:
sum_odd(range(1, 11))
Answer: A
To print the sum of odd numbers from 1 to 10, use
print(sum(range(1, 11, 2))).Discuss About this Question.
How can you read a line of text from the console, remove leading and trailing whitespaces, and convert it to uppercase?
A:
text = input().trim().upper()
B:
text = input().strip().uppercase()
C:
text = input().strip().upper()
D:
text = input().trim().uppercase()
Answer: C
To read a line of text from the console, remove leading and trailing whitespaces, and convert it to uppercase, use
input().strip().upper().Discuss About this Question.
How can you prompt the user to enter a floating-point number and round it to the nearest integer?
A:
float(input("Enter a number: ")).round()
B:
round(float(input("Enter a number: ")))
C:
int(input("Enter a number: "))
D:
round_int(input("Enter a number: "))
Answer: B
To prompt the user to enter a floating-point number and round it to the nearest integer, use
round(float(input("Enter a number: "))).Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.