0% found this document useful (0 votes)
2 views

Python Chapter10 - 50 Q & A

Chapter 10 covers essential Python concepts, including string manipulation, variable naming, data types, and basic operations. It addresses common errors and best practices, such as the importance of indentation and meaningful variable names. The chapter emphasizes user interaction through input and the flexibility it provides in programming.

Uploaded by

ck18065
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Chapter10 - 50 Q & A

Chapter 10 covers essential Python concepts, including string manipulation, variable naming, data types, and basic operations. It addresses common errors and best practices, such as the importance of indentation and meaningful variable names. The chapter emphasizes user interaction through input and the flexibility it provides in programming.

Uploaded by

ck18065
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Chapter 10 – Python

Each question is based on core Python concepts from Chapter 10: Introduction to Python.

1. 1. Why does Python give an error when we write: print('Hello)

Answer: Because the closing quote is missing. Python expects both opening and closing quotes for string values.

2. 2. What will be the result of: print(4 * '2')

Answer: 2222. Python repeats the string '2' four times using string multiplication.

3. 3. What is wrong in: name = input('Name') print(name)

Answer: Both statements are on the same line without a separator. Use a newline or a semicolon.

4. 4. Why is 5 + '3' invalid in Python?

Answer: You can't add a number and a string directly. Python needs both values to be of the same type.

5. 5. What is the type of value returned by input()?

Answer: String. Python returns everything from input() as text.

6. 6. Why does Python treat 'Data' and 'data' as different variables?

Answer: Because Python is case-sensitive. Uppercase and lowercase are treated as different.

7. 7. Why does print('Hello\nWorld') give output on two lines?

Answer: '\n' is a newline character that breaks the line.

8. 8. Why is '3' * 2 valid but 'three' * '2' is not?

Answer: You can multiply a string by an integer, but not by another string.

9. 9. What is the result of: print(9 % 2)?

Answer: 1. It's the remainder when 9 is divided by 2.

10. 10. Why is it better to use input() instead of hardcoding values?

Answer: It allows flexibility. Users can provide their own data.

11. 11. What will be the result of: print('5' + '3')?

Answer: 53. Because both are strings, so Python joins them.

12. 12. Why is 2value an invalid variable name?

Answer: Variable names cannot start with a number.

13. 13. What does the // operator do in Python?


Answer: It performs floor division and removes the decimal part.

14. 14. Predict the output: print(2 ** 3)

Answer: 8. This is exponentiation: 2 raised to the power of 3.

15. 15. What is the use of the print() function?

Answer: To display output on the screen.

16. 16. Why does print('Hello', end='!') print without newline?

Answer: 'end' changes the default ending character from newline to '!'.

17. 17. Predict output: print('A' * 3)

Answer: AAA. String 'A' repeated 3 times.

18. 18. What does len('Python') return?

Answer: 6. It counts all characters in the string.

19. 19. Why is print('My age is ' + 10) incorrect?

Answer: Because 10 is an integer. You must convert it to a string.

20. 20. Predict: print(int('5') + 5)

Answer: 10. '5' is converted to int and added.

21. 21. What happens if you use incorrect indentation in Python?

Answer: IndentationError. Python uses indentation to define blocks.

22. 22. Why should you use meaningful variable names?

Answer: To make your code easy to understand.

23. 23. What is the result of print('3' + str(4))?

Answer: 34. 4 is converted to string and concatenated.

24. 24. Why is print('It’s okay') an error?

Answer: Because the apostrophe ends the string early. Use double quotes or escape it.

25. 25. Predict: a = 3; b = 2; print(a % b)

Answer: 1. Remainder of 3 divided by 2.

26. 26. Why does print(10 / 2) return 5.0?

Answer: Because '/' returns a float even if the division is exact.

27. 27. What is the result of: print('3' * 4)?

Answer: 3333. String '3' repeated 4 times.


28. 28. Why is input() useful in programs?

Answer: It lets users interact with your program.

29. 29. What is the role of type() in Python?

Answer: It shows the data type of a variable or value.

30. 30. Predict: print(bool(''))

Answer: False. An empty string is considered False.

31. 31. Why is print(Hello) an error?

Answer: Hello is not in quotes. Python treats it as a variable.

32. 32. What will print('3' + '3') output?

Answer: 33. Strings are concatenated.

33. 33. Why is print('3' - '2') an error?

Answer: You cannot subtract strings.

34. 34. What is the result of: print(9 // 2)?

Answer: 4. Floor division removes the decimal.

35. 35. Why is using variables better than hardcoding?

Answer: You can reuse and update values without changing the code everywhere.

36. 36. What does print('Python\tRocks') output?

Answer: 'Python Rocks'. '\t' adds a tab space.

37. 37. Predict: print('Hello\nWorld')

Answer: Hello
World – printed on two lines.

38. 38. Why does int('ten') give an error?

Answer: 'ten' is not a number, so it can’t be converted to int.

39. 39. Predict output: print(4 * 2 + 1)

Answer: 9. Because multiplication happens before addition.

40. 40. What does print(type(3.5)) return?

Answer: <class 'float'>. 3.5 is a float.

41. 41. Why does '5' + 5 cause an error?

Answer: Cannot add string and integer directly.


42. 42. What does upper() do in Python?

Answer: Converts all characters to uppercase.

43. 43. Predict: print(5 == 5)

Answer: True. Because both values are equal.

44. 44. What is the result of print(bool(0))?

Answer: False. 0 is considered False in Python.

45. 45. Why use comments in code?

Answer: To explain what the code does, helpful for others or your future self.

46. 46. Why is name=input() more useful than name='Priya'?

Answer: It allows users to input their name instead of fixing it.

47. 47. Predict: print('A' * 0)

Answer: An empty string. Repeating 0 times gives nothing.

48. 48. What is the output of: print(2 + 3 * 4)?

Answer: 14. Multiplication is done before addition.

49. 49. What does print('Priya'.lower()) return?

Answer: priya. Converts all characters to lowercase.

50. 50. Why should variable names be meaningful?

Answer: It makes the code easier to understand and maintain.

You might also like