From 54ffb61a9f601e90c96816a128a648dcf93aec5d Mon Sep 17 00:00:00 2001 From: Oluwatoyin Date: Sat, 30 Jul 2022 16:31:11 +0100 Subject: [PATCH 1/3] odd and even numbers solution added --- DsaPlayGround/PlayGround/task4.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 DsaPlayGround/PlayGround/task4.py diff --git a/DsaPlayGround/PlayGround/task4.py b/DsaPlayGround/PlayGround/task4.py new file mode 100644 index 0000000..7b23c5a --- /dev/null +++ b/DsaPlayGround/PlayGround/task4.py @@ -0,0 +1,20 @@ +# Question +# Array and String Manipulation + +# Program to print Odd and Even Numbers from an integer Array. +# Input: +#[1, 2, 5, 6, 3, 2] + + +input = [1, 2, 5, 6, 3, 2] + + +def even(): + for x in input: + if x % 2 == 0: + print(x, 'is an even number') + else: + print(x, 'is an odd number') + + +even() From 6d1149e1d4767555e32fe0d25d11c67e5ee58eec Mon Sep 17 00:00:00 2001 From: Oluwatoyin Date: Tue, 2 Aug 2022 21:24:51 +0100 Subject: [PATCH 2/3] task 5 soluttion added --- DsaPlayGround/PlayGround/FizzBuzz.py | 23 +++++++++++++++++++++ DsaPlayGround/PlayGround/username.py | 30 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 DsaPlayGround/PlayGround/FizzBuzz.py create mode 100644 DsaPlayGround/PlayGround/username.py diff --git a/DsaPlayGround/PlayGround/FizzBuzz.py b/DsaPlayGround/PlayGround/FizzBuzz.py new file mode 100644 index 0000000..3a0218b --- /dev/null +++ b/DsaPlayGround/PlayGround/FizzBuzz.py @@ -0,0 +1,23 @@ +def fizzbuzz(): + count = 3 + while True: + + user_input = int(input('Enter a positive integer: ')) + if count == 0: + break + if user_input <= 0: + count -= 1 + print( + f'you have {count} trials left, you can only enter a positivenumber,try again!\n') + else: + if user_input % 3 == 0 and user_input % 5 == 0: + print('FizzBuzz') + elif user_input % 5 == 0: + print('Buzz') + elif user_input % 3 == 0: + print('Fizz') + else: + print(str(user_input)) + + +fizzbuzz() diff --git a/DsaPlayGround/PlayGround/username.py b/DsaPlayGround/PlayGround/username.py new file mode 100644 index 0000000..3c12f28 --- /dev/null +++ b/DsaPlayGround/PlayGround/username.py @@ -0,0 +1,30 @@ +import string + + +valid_character = set(string.ascii_letters + string.digits + '_' + '-') + + +message = ('@User_One @UserABC! Have you seen this from @Userxyz?').split() + + +def user_name(message, k): + key = 1 + + user_dict = {key: ' '} + for word in message: + if word.startswith('@'): + username = word[1:] + for i in range(len(username)): + if not (set(username[i]).issubset(valid_character)): + username = username[0:i] + user_dict[key] = username + key += 1 + try: + return user_dict[k] + except: + print(' ') + + +print(user_name(message, 3)) +print(user_name(message, 2)) +print(user_name(message, 1)) From 570340b875c6a435aa9b0b401dcf0cd216cc52a3 Mon Sep 17 00:00:00 2001 From: Oluwatoyin Date: Tue, 2 Aug 2022 21:37:39 +0100 Subject: [PATCH 3/3] code formater turned off --- DsaPlayGround/PlayGround/FizzBuzz.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/DsaPlayGround/PlayGround/FizzBuzz.py b/DsaPlayGround/PlayGround/FizzBuzz.py index 3a0218b..f0dfb73 100644 --- a/DsaPlayGround/PlayGround/FizzBuzz.py +++ b/DsaPlayGround/PlayGround/FizzBuzz.py @@ -1,14 +1,12 @@ def fizzbuzz(): count = 3 while True: - user_input = int(input('Enter a positive integer: ')) if count == 0: break if user_input <= 0: count -= 1 - print( - f'you have {count} trials left, you can only enter a positivenumber,try again!\n') + print(f'you have {count} trials left, you can only enter a positivenumber,try again!\n') else: if user_input % 3 == 0 and user_input % 5 == 0: print('FizzBuzz')