0% found this document useful (0 votes)
9 views5 pages

Python Week1 Assignment

The document is a Python assignment that covers basic programming concepts such as variable creation, naming conventions, data types, and arithmetic operations. It includes examples of variable assignment, type identification, and type conversion, along with simple calculations and the use of assignment operators. The code snippets demonstrate practical applications of these concepts in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Python Week1 Assignment

The document is a Python assignment that covers basic programming concepts such as variable creation, naming conventions, data types, and arithmetic operations. It includes examples of variable assignment, type identification, and type conversion, along with simple calculations and the use of assignment operators. The code snippets demonstrate practical applications of these concepts in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

# -*- coding: utf-8 -*-

"""python week1 assignment

Automatically generated by Colab.

Original file is located at


https://colab.research.google.com/drive/1d4bkP06KUuiXcq8jfjir2kX1b0-
UJ6Yv
"""

"""python assignment
## **python assignment**

creating a *variable*
"""

name="alice"
age=30
is_student=True

"""using variables in expression

"""

width=20
height=10
area=width*height
print(area)

"""variable naming convention"""

my_lucky_num=6
1mynum=6 # it is invalid variable naming because i used a num at the
starting of variable name

"""variable reassignment"""

count=0
count=count+1
print(count)

"""simple calculations"""

num1=20
num2=10
sum=num1+num2
print(sum)
sub=num1-num2
print(sub)
print(num1*num2)
print(num1/num2)

"""identification of data types"""

"""1.age = 25
2. name = "Alice"
3. is_raining = True
4. pi = 3.14159
5. empty_value = None
6. count = 10
7. price = 9.99
8. is_active = False
9. city = "New York"
10. temperature = 25.5
11. student_names = ["Alice", "Bob", "Charlie"]
12. grades = (85, 90, 78)
13. person = {'name': 'Alice', 'age': 30}
14. colors = {'red', 'green', 'blue'}
15. my_range = range(5)
16. x = 10 + 5j
17. flag = True
18. result = None
19. message = "Hello World!"
20. number = 0 """
print(type(25))
print(type("Alice"))
print(type(True))
print(type(3.14159))
print(type(None))
print(type(10))
print(type(9.99))
print(type(False))
print(type("New York"))
print(type(25.5))
print(type(["Alice", "Bob", "Charlie"]))
print(type((85, 90, 78)))
print(type({'name': 'Alice', 'age': 30}))
print(type({'red', 'green', 'blue'}))
print(type(range(5)))
print(type(10 + 5j))
print(type(True))
print(type(None))
type("Hello World!")
#type(0 """") it is error type

"""data type conversion"""

"""1. age = 30 (convert to string)


2. price = "9.99" (convert to float)
3. status = "True" (convert to boolean)
4. quantity = "5" (convert to integer)
5. num = 10 (convert to float)
6. pi = 3.14159 (convert to integer)
7. is_raining = True (convert to string)
8. count = 100 (convert to string)
9. temperature = 25.5 (convert to integer)
10. flag = True (convert to integer)
11. price_str = "19.99" (convert to float)
12. quantity_str = "10" (convert to integer)
13. status_str = "False" (convert to boolean)
14. age_str = "35" (convert to integer)
15. pi_str = "3.14" (convert to float)
16. is_raining_str = "True" (convert to boolean)
17. number_str = "10" (convert to integer)
18. flag_str = "True" (convert to boolean)
19. count_str = "50" (convert to integer)
20. temperature_str = "20.2" (convert to float) """
age=str(30)
print(age)
price=float("9.99")
print(price)
status=bool("True")
print(status)
quantity=int("5")
print(quantity)
num=float(10)
print(num)
pi=int(3.14159)
print(pi)
is_raining=str(True)
print(is_raining)
count=str(100)
print(count)
temperature=int(25.5)
print(temperature)
flag=int(True)
print(flag)
price_str=float("19.99")
print(price_str)
quantity_str=int("10")
print(quantity_str)
status_str=bool("False")
print(status_str)
age_str=int("35")
print(age_str)
pi_str=float("3.14")
print(pi_str)
is_raining_str=bool("True")
print(is_raining_str)
number_str=int("10")
print(number_str)
#flag_str=int("True") flag value cannot convert into interger
#print(flag_str)
count_str=int("50")
print(count_str)
temperature_str=float("20.2")
print(temperature_str)

"""arthmatic operations

"""

x=10 #1
y=5
result=x-y
print(result)

x=3
y=4
result=x/y
print(result)
x=15
y=4
result=x%y
print(result)

x=2
y=3
result=x//y
print(result)

x=10
y=5
result=(x+y)*2
print(result)

x=10
y=5
result= x<=y
print(result)

x=5
y=5
result= x!=y
print(result)

x = 10
y = 5
result = x<y
print(result)

x = 5
y = 10
result = x>y
print(result)

x = True
y = False
result = x or y
print(result)

x = True
y = False
result = x and y
print(result)

x = True
result = x == False
print(result)

"""assignment operators"""

x = 10
x += 5
print(x)

x=5
x*=3
print(x)
x=20
x/=2
print(x)

You might also like