QuizzesType Conversion & Reading Input — Concept Check
intermediate
python

Type Conversion & Reading Input — Concept Check

Questions on Type Conversion & Reading Input. input() always returns a string — converting between str, int, float, list and friends explicitly is how Python programs take and validate data, and how every DSA judge feeds your code.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Type Conversion & Reading Input — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.You read input using input() and want to convert '123.45' to an integer. What will happen if you use int(input())?

    • AIt will raise a ValueError.
    • BIt will convert to 123.
    • CIt will return 0.
    • DIt will convert to 123.45.
  2. 2.A Python program reads input using input() and splits it using split(). What type is each element of the resulting list?

    • Afloat
    • Bint
    • Cstr
    • Dlist
  3. 3.You have a list of strings ['1', '2', '3'] and want to convert it to [1, 2, 3]. Which method is correct?

    • Alist(int(['1', '2', '3']))
    • Blist(map(int, ['1', '2', '3']))
    • Cint(['1', '2', '3'])
    • Dmap(int, ['1', '2', '3'])
  4. 4.You execute the code: int('0x10'). What is the output?

    • A0
    • B10
    • CRaises ValueError
    • D16
  5. 5.A program reads two integers from a single line of input. Which code snippet correctly achieves this?

    • Aa, b = list(map(int, input()))
    • Ba, b = map(int, input().split())
    • Ca, b = int(input()), int(input())
    • Da, b = int(input().split())
  6. 6.You want to convert a string 'True' to a boolean. Which method will give the correct result?

    • Abool('True')
    • Bbool(True)
    • Cbool(str('True'))
    • Dbool(int('True'))
  7. 7.What happens when you execute list('123') in Python?

    • A['1', '2', '3']
    • B[123]
    • C['123']
    • DRaises TypeError
  8. 8.You have a string '4.2' and want to convert it to an integer. What is the correct approach?

    • Aint('4.2')
    • Bfloat(int('4.2'))
    • Cint('4.2', 10)
    • Dint(float('4.2'))