diff --git a/Challenge questions/challenges/ch_1.py b/Challenge questions/challenges/ch_1.py new file mode 100644 index 0000000..d3fdf83 --- /dev/null +++ b/Challenge questions/challenges/ch_1.py @@ -0,0 +1,10 @@ +# Challenge:1 +# Write a Code that accepts String in a format like "My name is someone", +# then it has to be formatted into "MyNameIsSomeone" and then back to original + +user_input = input("Enter String: ") +user_str = {} +for i in user_input.split(" "): + user_str[i] = i.capitalize() +print("Camel String %s", "".join(user_str.values())) +print("Back to original %s", " ".join(user_str.keys())) diff --git a/Challenge questions/challenges/ch_4.py b/Challenge questions/challenges/ch_4.py new file mode 100644 index 0000000..e2c5a45 --- /dev/null +++ b/Challenge questions/challenges/ch_4.py @@ -0,0 +1,9 @@ +# Challenge:4 +# Reading from a CSV file and printing all columns as rows. + + +import pandas as pd + +pd_data = pd.read_csv("test.csv") +for col in pd_data.columns: + print(pd_data[col].values) diff --git a/Challenge questions/challenges/ch_5.py b/Challenge questions/challenges/ch_5.py new file mode 100644 index 0000000..ea1c89f --- /dev/null +++ b/Challenge questions/challenges/ch_5.py @@ -0,0 +1,25 @@ +# Challenge:5 +#Given Strings of code equations like, "45 >= 67 56==70 30 <= 78" and output should be binary "0 0 1" +# { input is seprated with space and output should be on new line} + +import re +input = "45>=67 56==70 30<=78" +expected = [] +input_list = input.split(" ") +for value in input_list: + res = re.match("([0-9]+)([\+=<>]+)([0-9]+)", value) + if res is not None: + if res.group(2) == "==": + expected.append(1 if int(res.group(1)) == int(res.group(3)) else 0) + elif res.group(2) == ">=": + expected.append(1 if int(res.group(1)) >= int(res.group(3)) else 0) + elif res.group(2) == "<=": + expected.append(1 if int(res.group(1)) <= int(res.group(3)) else 0) + elif res.group(2) == "<": + expected.append(1 if int(res.group(1)) < int(res.group(3)) else 0) + elif res.group(2) == ">": + expected.append(1 if int(res.group(1)) > int(res.group(3)) else 0) + else: + print("operation error") + +print(expected) diff --git a/Challenge questions/challenges/ch_6.py b/Challenge questions/challenges/ch_6.py new file mode 100644 index 0000000..bfa2a29 --- /dev/null +++ b/Challenge questions/challenges/ch_6.py @@ -0,0 +1,11 @@ +#Challenge 6 +#Write a program that converts text written numbers (Ex: Thirty-One) to its numeric form (Ex: 31) +# and perform the opposite. Input: 31 Output: (Thirty-One) +from word2number import w2n +from num2words import num2words + +print(num2words(42)) +print(w2n.word_to_num('112')) +print(w2n.word_to_num('point one')) + +print(num2words(100)) diff --git a/Challenge questions/challenges/test.csv b/Challenge questions/challenges/test.csv new file mode 100644 index 0000000..fdfee99 --- /dev/null +++ b/Challenge questions/challenges/test.csv @@ -0,0 +1,4 @@ +col1,col2,col3 +1,3,4 +4,5,3 +2,9,0