Problem 1
nums = [2, 3, 3, 4, 5, 5, 6, 8, 9, 9, 10]
l = len(nums)
if l % 2 == 0:
median = (nums[l // 2 - 1] + nums[l // 2]) / 2
else:
median = nums[l // 2]
print("The median of these numbers is", median)
The median of these numbers is 5
Problem 2
import random
num = random.randint(1,100)
print("guess a number 1-100. i'll tell you wether to go higher or lower")
while True:
guess = int(input("Input your guess!"))
if guess < num:
print("try going higher!")
if guess > num:
print("try going lower!")
if guess == num:
print("you got it! the number was ",num)
break
guess a number 1-100. i'll tell you wether to go higher or lower
try going higher!
try going higher!
try going higher!
try going lower!
try going higher!
you got it! the number was 79