Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#python-challenge - write challenge code #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Challenge questions/challenges/ch_1.py
Original file line number Diff line number Diff line change
@@ -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()))
9 changes: 9 additions & 0 deletions Challenge questions/challenges/ch_4.py
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 25 additions & 0 deletions Challenge questions/challenges/ch_5.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions Challenge questions/challenges/ch_6.py
Original file line number Diff line number Diff line change
@@ -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))
4 changes: 4 additions & 0 deletions Challenge questions/challenges/test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
col1,col2,col3
1,3,4
4,5,3
2,9,0