diff --git a/DsaPlayGround/PlayGround/FizzBuzz.py b/DsaPlayGround/PlayGround/FizzBuzz.py new file mode 100644 index 0000000..f0dfb73 --- /dev/null +++ b/DsaPlayGround/PlayGround/FizzBuzz.py @@ -0,0 +1,21 @@ +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/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() 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))