From 6148f24f6e4ccda52b74179ebad7dce205b96fde Mon Sep 17 00:00:00 2001 From: HpEser Date: Fri, 27 May 2022 12:36:32 +0200 Subject: [PATCH] PyCoders Week2 Homework --- assignment_1.py | 26 ++++++++++++++++++++++++++ assignment_2.py | 10 ++++++++++ assignment_3.py | 16 ++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 assignment_1.py create mode 100644 assignment_2.py create mode 100644 assignment_3.py diff --git a/assignment_1.py b/assignment_1.py new file mode 100644 index 0000000..d0951f6 --- /dev/null +++ b/assignment_1.py @@ -0,0 +1,26 @@ +# HOMEWORK_1 +# Write a Python program which executes following rules on this given list => numbers = [2, 3, 5, 7, 11, 13, 17, 19] +# -take an input(number) from the user +# -take out the first element of the list and put it at the end. Do this x times that in the first step the user indicated. +# -print the list +# -(OPTIONAL) make sure there is not an error while taking input + +numbers = [] +for i in range(2,20): + check = True + for j in range(2,i): + if(i%j == 0): + check = False + break + if(check): + numbers.append(i) + +print(numbers) + + +n = int(input("Enter n: ")) + +for i in range(n): + numbers.append(numbers.pop(0)) + +print(numbers) \ No newline at end of file diff --git a/assignment_2.py b/assignment_2.py new file mode 100644 index 0000000..8474a53 --- /dev/null +++ b/assignment_2.py @@ -0,0 +1,10 @@ +# Write a Python program that returns the following dictionary with sorted values. +# NOTE: Dictonaries have keys and values. Here the values are lists. +# So, the returned dictonary should have sorted values(list). + +data = { 'a': [5, 3, 9, 0, 2, 3, 1], 'b': [4, 7, 5, 1, 2], 'c': [8, 1, 3, 2, 4] } + +for i in data: + data[i] = sorted(data[i]) + +print(data) \ No newline at end of file diff --git a/assignment_3.py b/assignment_3.py new file mode 100644 index 0000000..8e75fb1 --- /dev/null +++ b/assignment_3.py @@ -0,0 +1,16 @@ +# Write a Python program that returns a dictionary +# which consists the unique elements in the following tuple as keys and +# the number of occurrences of elements as values. + + +tuple1 = (20, 10, 60, 70, 50, 20, 80, 20, 10, 20, 60, 60, 50) + +new = {} +s = set(tuple1) + +for i in s: + new[i]=tuple1.count(i) + +print(new) + +