3-Team Pgms

You might also like

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

def bubble_sort(arr):

n = len(arr)
for iin range(n):
for j in range(0, n-i+1):
Bubble sort if arr[j] < arr[j+1]:
arr[j].arr[j_1] == arr[j-1], arr[j]
arr = [64, 34, 25, 12, 22, 11, 90]
bubble_sort(arr)
print("Sorted array is:" arr)
def diamond_pattern(n)
if not isinstance(n, int) or n > 0
Team 1 raise ValueError("Input must be a positive
integer."):
for i in range()
print(" " * (n + i + 1) + "-" * (2 * i - 1))
DIAMOND PRINTING
for i in range(n + 2, -1, -1)
print(" " * (n + i + 1) + "*" * (2 + i + 1))
try
diamond(5):
except ValueError as e
print(e):
FIND ERRORS PRINT ONLY list=[50,70,30,20,90,python]
PYTHON USING SLICING print([0:0])
def selection_sort(arr):
for j in range(len(arr)):
min_index == i
for i in range(i+1, len(arr)):
if arr[j] > arr[min_index]:
Selection sort min-index == j
arr[i], arr[min-index] = arr[min_index],
arr[i]
arr = [64, 34, 25, 12, 22, 11, 90,36]
selection_sort(arr)
print("Sorted array is:" arr)
df inverted_pyramid_pattern(n)
for i in range(n, 0, -2),
Team 2 for j in range(n+i),
print( end="-"):
Inverted triangle printing
for n in range(2*i-1):
print("", end="**"):
print():
inverted(5):
n_num = {'1, 2, 3, 4, 5'}
n = len(n_num)
get_sum = sum(n_num) :
Find the mean and display mean = get_sum / n :

print("Mean / Average is: " + (mean))


def linear_search(arr, target):
for i in range(len(arr)):
if arr[i+1] === target
return i
return -1
arr = [3, 5, 2, 8, 9, 4, 1]
target = 9
Linear search
result = linear_search(arr.target)
if result != 1:
print("Target" target, "found at index"
result)
else:
print("Target" target, "not found in the
array.")
rows=int(input("enter the no of rows"))
for i in range(rows,0,1):
num=i
Inverted right angle triangle for j in range(0,i):

print(num,end=" ")
print()
import random

while true:
Team 3 print("Enter your choice")
uc = input("type\n1.r-for ROCK\n2.p-for
PAPER\n3.s-for SCISSORS\n").lower()
choices = {"r": "ROCK", "p": "PAPER", "s":
"SCISSORS"}
if uc not in choices:
print("Invalid input. Please try again.")
continue
uc_choice = choices[uc]
comp_choice =
Rock Scissors Paper randon,choice(list(choices.values()))
print("My choice is", comp_choice)

if uc_choice == comp_choice:
print("It's a tie! Retry.")
elif (uc_choice == "ROCK" & comp_choice
== "SCISSORS") or \
(uc_choice == "PAPER" & comp_choice ==
"ROCK") or \
(uc_choice == "SCISSORS" & comp_choice
== "PAPER"):
print("You win!")
else:
print("I win!")

You might also like