ahamed-4 assigment

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Assignment-4

1. What's Your Name?

Program:
def print_full_name(first, last):

print(f"Hello {first} {last}! You just delved into python.")

if __name__ == '__main__':
first_name = input()
last_name = input()
print_full_name(first_name, last_name)

2. sWaP cASE

Program:

def swap_case(s):

return s.swapcase()

if __name__ == '__main__':
s = input()
result = swap_case(s)
print(result)

3. Lists

Program:

my_list = []
N = int(input())
for _ in range(N):

command = input().strip().split()
if command[0] == "insert":
my_list.insert(int(command[1]), int(comma
nd[2]))
elif command[0] == "print":
print(my_list)
elif command[0] == "remove":
my_list.remove(int(command[1]))
elif command[0] == "append":
my_list.append(int(command[1]))
elif command[0] == "sort":
my_list.sort()
elif command[0] == "pop":
my_list.pop()
elif command[0] == "reverse":
my_list.reverse()

4. List Comprehension

Program:

if __name__ == '__main__':

x = int(input())
y = int(input())
z = int(input())
n = int(input())
coordinates = [[i, j, k] for i in range(x + 1) for
j in range(y + 1) for k in range(z + 1) if (i + j + k)
!= n]
print(coordinates)

You might also like