Statement of Completion#3793fc46
Python Basics
easy
Python Syntax and Structure Guide
Resolution
Activities
Project.ipynb
Printing Statements (print()
function)¶
In [ ]:
print("Hello, World!")
In [ ]:
print("Hello, world!")
print("The answer is:", 42)
In [ ]:
print("Hello,", "world!")
print("Welcome", "to", "DataWars")
In [ ]:
print("Hello,", "Welcome to DataWars!")
Activity 1. Select the correct output¶
In [ ]:
Activity 2. Write the correct code¶
In [ ]:
Activity 3. Which of the following is the correct way to print “Hi there!” in Python 3?¶
In [ ]:
Comments (Single-line and Multi-line)¶
Activity 4. Executing Comments¶
In [ ]:
Activity 5. What is the correct error¶
In [ ]:
Running Python Scripts (.py
Files)¶
Activity 6. Select the correct option for running script with arguments¶
Activity 7. What will be the output of code given¶
In [ ]:
Activity 8. Create a python script¶
Indentation Rules¶
In [ ]:
if True:
print("This line is indented and belongs to the if block")
print("This line is not indented and runs after the if block")
Wrong Indentation:
It will give an error because the indentation is wrong.
In [ ]:
if True:
print("This line is not indented and will cause an IndentationError")
Variables and Assignments¶
Dynamic Typing:
In [ ]:
x = 10 # x is an integer
y = "Hello" # y is a string
z = 3.14 # z is a float
Assignment in Python
In [ ]:
x = 5 # Assigns the value 5 to x
name = "Alice" # Assigns the string "Alice" to name
Multiple Assignments
In [ ]:
a, b, c = 1, 2, 3 # a = 1, b = 2, c = 3
x = y = z = 0 # x, y, and z are all assigned the value 0
Swapping Variables
In [ ]:
a, b = b, a
Reassigning Variables
In [ ]:
x = 10 # Initially an integer
x = "Python" # Reassigned to a string
Global and Local Variables
In [ ]:
x = 10 # Global variable
def example():
y = 5 # Local variable
print(y)
example()
print(x)
Special Cases
In [ ]:
data = [1, 2, 3]
a, b, c = data # a = 1, b = 2, c = 3
print(a)
print(b)
print(c)
Activity 9. Name it Right!¶
In [ ]:
User Input (input() function)¶
In [ ]:
name = input("What is your name? ")
print("Hello, " + name + "!")
Activity 10. Convert Fahrenheit to Celsius¶
In [ ]: