CA 01 - Python Variables, Print
These task are done in jupyter lite and Idk how to submit so i copied them and pasted here
TASK-1
print("hello world")
hello world
name = "Adharsh"
print(name)
Adharsh
name = "Adharsh"
age = 19
city = "chennai"
print(name, age, city)
Adharsh 19 chennai
print(f"Hello, My name is {name} and I'm {age} years old living at {city}")
Hello, My name is Adharsh and I'm 19 years old living at chennai
print("Hello" + " " + "world")
Hello world
print("Line1\nLine2\nLine3")
Line1
Line2
Line3
print('He said, "Hello, world!"')
He said, "Hello, world!"
print("C:\\Users\\Name")
C:\Users\Name
print(5+3)
8
print("hello","world",sep="-")
hello-world
print("hello","world",sep=" ")
hello world
is_active = True
print(is_active)
True
print("hello\nhello\nhello")
hello
hello
hello
temperature = "The temperature is 22.5 degrees Celsius"
print(temperature)
The temperature is 22.5 degrees Celsius
name="Adharsh"
age=19
city="chennai"
output = "Name: {}, Age: {}, City: {}".format(name, age, city)
print(output)
Name: Adharsh, Age: 19, City: chennai
pi = round(3.14159,2)
print(pi)
3.14
print("Left" + " " * 10 + "Right")
Left Right
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TASK-2
name = "Adharsh"
print(name)
Adharsh
age = 19
print(age)
19
age = 20
print(age)
20
a, b, c = 5, 10, 15
print(a, b, c)
5 10 15
x = 5
y = 10
print("Before swapping:", x, y)
Before swapping: 5 10
x, y = y, x
print("After swapping:", x, y)
After swapping: 10 5
PI = 3.14159
print(PI)
3.14159
radius = 5
area = PI * radius * radius
print("Area of circle:", area)
Area of circle: 78.53975
LENGTH = 10
WIDTH = 5
area_rectangle = LENGTH * WIDTH
print("Area of rectangle:", area_rectangle)
Area of rectangle: 50
radius = 5
circumference = 2 * PI * radius
print("Circumference of circle:", circumference)
Circumference of circle: 31.4159
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TASK-3
items = ["Notebook", "Pencil", "Eraser", "Ruler", "Marker"]
print(items[2])
Eraser
items.append("Glue Stick")
print(items)
['Notebook', 'Pencil', 'Eraser', 'Ruler', 'Marker', 'Glue Stick']
items.insert(2, "Highlighter")
print(items)
['Notebook', 'Pencil', 'Highlighter', 'Eraser', 'Ruler', 'Marker', 'Glue Stick']
items.remove("Ruler")
print(items)
['Notebook', 'Pencil', 'Highlighter', 'Eraser', 'Marker', 'Glue Stick']
print(items[:3])
['Notebook', 'Pencil', 'Highlighter']
upper_items = [i.upper() for i in items]
print(upper_items)
['NOTEBOOK', 'PENCIL', 'HIGHLIGHTER', 'ERASER', 'MARKER', 'GLUE STICK']
print("Marker" in items)
True
print(len(items))
6
items.sort()
print(items)
['Eraser', 'Glue Stick', 'Highlighter', 'Marker', 'Notebook', 'Pencil']
items.reverse()
print(items)
['Pencil', 'Notebook', 'Marker', 'Highlighter', 'Glue Stick', 'Eraser']
delivery = [["Notebook", "10AM"], ["Pencil", "11AM"]]
print(delivery[0])
['Notebook', '10AM']
print(items.count("Ruler"))
0
print(items.index("Pencil"))
0
items.extend(["Pen", "Sharpener"])
print(items)
['Pencil', 'Notebook', 'Marker', 'Highlighter', 'Glue Stick', 'Eraser', 'Pen', 'Sharpener']
items.clear()
print(items)
[]
repeat_list = ["Notebook"] * 3
print(repeat_list)
['Notebook', 'Notebook', 'Notebook']
items = ["Notebook", "Pencil", "Eraser"]
length_list = [[i, len(i)] for i in items]
print(length_list)
[['Notebook', 8], ['Pencil', 6], ['Eraser', 6]]
filtered = [i for i in items if "e" in i.lower()]
print(filtered)
['Notebook', 'Pencil', 'Eraser']
items = ["Notebook", "Pencil", "Notebook", "Eraser"]
unique_items = list(set(items))
print(unique_items)
['Notebook', 'Pencil', 'Eraser']
Comments
Post a Comment