Python beginners sheet, Cheat Sheet of Programming Languages

Two Guesses for the Silver Dollar. Draw the game tree for problem 1, if when I is unsuccessful in his first attempt to find the dollar, he is given a second chance to choose a room and search for it with the same probabilities of success, independent of his previous search. (Player II does not get to hide the dollar again.

Typology: Cheat Sheet

2024/2025

Uploaded on 03/09/2025

noha-elsayed
noha-elsayed 🇪🇬

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Types and Variables
1. Write a Python program to print the type of the following variables: a = 5, b =
5.0, c = "Hello".
2. Create a variable x and assign it the value 10. Print the value of x.
3. Swap the values of two variables a = 5 and b = 10 without using a third variable.
4. Convert the integer 123 to a string and print its type.
5. Convert the string "3.14" to a float and print its type.
6. Create a variable name and assign it your name. Print the value of name.
7. Create a variable age and assign it your age. Print the value of age.
8. Create a variable is_student and assign it a boolean value (True or False). Print
the value of is_student.
9. Create a variable pi and assign it the value 3.14159. Print the value of pi.
10. Create a variable complex_num and assign it the value 2 + 3j. Print the value of
complex_num.
Strings
11. Create a string s = "Hello, World!" and print its length.
12. Print the first character of the string s = "Python".
13. Print the last character of the string s = "Programming".
14. Print the substring "World" from the string s = "Hello, World!".
15. Convert the string s = "hello" to uppercase and print the result.
16. Convert the string s = "HELLO" to lowercase and print the result.
17. Replace the word "World" with "Python" in the string s = "Hello, World!".
18. Check if the string s = "Python" starts with the letter "P".
19. Check if the string s = "Python" ends with the letter "n".
20. Split the string s = "Hello, World!" into a list of words using the comma as a
delimiter.
Python Syntax
21. Write a Python program to print "Hello, World!".
22. Write a Python program to print your name and age on separate lines.
23. Write a Python program to print the sum of two numbers 5 and 10.
24. Write a Python program to print the product of two numbers 3 and 7.
25. Write a Python program to print the result of 2 ** 3 (2 raised to the power of 3).
pf3
pf4

Partial preview of the text

Download Python beginners sheet and more Cheat Sheet Programming Languages in PDF only on Docsity!

Data Types and Variables

1. Write a Python program to print the type of the following variables: a = 5 , b =

5.0, c = "Hello".

2. Create a variable x and assign it the value 10. Print the value of x.

3. Swap the values of two variables a = 5 and b = 10 without using a third variable.

4. Convert the integer 123 to a string and print its type.

5. Convert the string "3.14" to a float and print its type.

6. Create a variable name and assign it your name. Print the value of name.

7. Create a variable age and assign it your age. Print the value of age.

8. Create a variable is_student and assign it a boolean value (True or False). Print

the value of is_student.

9. Create a variable pi and assign it the value 3.14159. Print the value of pi.

10. Create a variable complex_num and assign it the value 2 + 3j. Print the value of

complex_num.

Strings

11. Create a string s = "Hello, World!" and print its length.

12. Print the first character of the string s = "Python".

13. Print the last character of the string s = "Programming".

14. Print the substring "World" from the string s = "Hello, World!".

15. Convert the string s = "hello" to uppercase and print the result.

16. Convert the string s = "HELLO" to lowercase and print the result.

17. Replace the word "World" with "Python" in the string s = "Hello, World!".

18. Check if the string s = "Python" starts with the letter "P".

19. Check if the string s = "Python" ends with the letter "n".

20. Split the string s = "Hello, World!" into a list of words using the comma as a

delimiter.

Python Syntax

21. Write a Python program to print "Hello, World!".

22. Write a Python program to print your name and age on separate lines.

23. Write a Python program to print the sum of two numbers 5 and 10.

24. Write a Python program to print the product of two numbers 3 and 7.

25. Write a Python program to print the result of 2 ** 3 (2 raised to the power of 3).

26. Write a Python program to print the remainder when 10 is divided by 3.

27. Write a Python program to print the result of 10 / 3 and 10 // 3.

28. Write a Python program to print the result of 10 % 3.

29. Write a Python program to print the result of 10 + 3 * 2.

30. Write a Python program to print the result of (10 + 3) * 2.

Jupyter Notebook

31. Create a Jupyter Notebook cell and print "Hello, Jupyter!".

32. Create a Jupyter Notebook cell and print the result of 5 + 5.

33. Create a Jupyter Notebook cell and print the type of the variable x = 10.

34. Create a Jupyter Notebook cell and print the length of the string s = "Python".

35. Create a Jupyter Notebook cell and print the result of 10 / 2.

36. Create a Jupyter Notebook cell and print the result of 10 ** 2.

37. Create a Jupyter Notebook cell and print the result of 10 % 3.

38. Create a Jupyter Notebook cell and print the result of 10 + 3 * 2.

39. Create a Jupyter Notebook cell and print the result of (10 + 3) * 2.

40. Create a Jupyter Notebook cell and print the result of 10 / 3.

Number Types: Integers and Floats

41. Create a variable x and assign it the value 10. Print the value of x.

42. Create a variable y and assign it the value 3.14. Print the value of y.

43. Convert the integer 10 to a float and print the result.

44. Convert the float 3.14 to an integer and print the result.

45. Print the result of 10 + 3.14.

46. Print the result of 10 - 3.14.

47. Print the result of 10 * 3.14.

48. Print the result of 10 / 3.14.

49. Print the result of 10 ** 3.14.

50. Print the result of 10 % 3.14.

Errors in Python

51. Write a Python program that causes a SyntaxError and explain how to fix it.

52. Write a Python program that causes a NameError and explain how to fix it.

53. Write a Python program that causes a TypeError and explain how to fix it.

Data Structures: Sets

81. Create a set s = {1, 2, 3} and print its length.

82. Add the element 4 to the set s = {1, 2, 3}.

83. Remove the element 2 from the set s = {1, 2, 3}.

84. Create a set s = {1, 2, 3} and print its type.

85. Create a set s = {1, 2, 3} and convert it to a list.

86. Create a set s = {1, 2, 3} and print the result of s.union({4, 5}).

87. Create a set s = {1, 2, 3} and print the result of s.intersection({2, 3, 4}).

88. Create a set s = {1, 2, 3} and print the result of s.difference({2, 3, 4}).

89. Create a set s = {1, 2, 3} and print the result of

s.symmetric_difference({2, 3, 4}).

90. Create a set s = {1, 2, 3} and print the result of s.issubset({1, 2, 3, 4}).

Data Structures: Dictionaries

91. Create a dictionary d = {"a": 1, "b": 2} and print its length.

92. Access the value associated with the key "a" in the dictionary d = {"a": 1,

"b": 2}.

93. Change the value associated with the key "a" to 3 in the dictionary d = {"a": 1,

"b": 2}.

94. Create a dictionary d = {"a": 1, "b": 2} and print its type.

95. Create a dictionary d = {"a": 1, "b": 2} and convert it to a list of tuples.

96. Create a dictionary d = {"a": 1, "b": 2} and print the result of d.keys().

97. Create a dictionary d = {"a": 1, "b": 2} and print the result of d.values().

98. Create a dictionary d = {"a": 1, "b": 2} and print the result of d.items().

99. Create a dictionary d = {"a": 1, "b": 2} and print the result of d.get("a").

100. Create a dictionary d = {"a": 1, "b": 2} and print the result of

d.pop("a").