Search the courses, subjects, tracks, games and features, or jump straight to a page.
5 cards from this section. Quick, good the night before a test.
Create the variables book holding "Python Basics", pages holding 320 and rating holding 4.5, then print each value with its type.
Use `print(value, type(value))` to show a value and its type on one line.
Which of these are valid Python variable names: total_marks, 2fast, first-name, _count, else, Price?
Check the first character, the characters allowed after it, and whether the word is reserved by Python.
Which type does Python give the value "3.14" when it is written with quotes?
Look at the quotes before you look at the digits.
What is the value of int(9.8)?
int() cuts off the decimal part.
Build a student-profile program. Store a name (str), an age given as the text "19", a height in metres (float), whether the student has a library card (bool) and a middle name that is not known yet (None). Convert the age to an int, print every variable with its type, and print the student's age in months.
Convert `age_text` with `int()` before multiplying, otherwise `"19" * 12` repeats the text twelve times.
A sensor sends three readings as text: "21", "22.5" and "" (empty, because one reading failed). Convert the first two to numbers and print their sum, use bool() to print whether the third reading contains any data, and print the second reading as a whole number. Explain why int("22.5") would not work.
An empty string converts to False with `bool()`, and `int()` only accepts text that looks like a whole number.
6 more questions in this section. Enroll free to practise them all.
Enroll free