From cf781174d1a26eb489d482e8daf30bdb86f5afb0 Mon Sep 17 00:00:00 2001 From: Heyyayaya <116991476+Heyyayaya@users.noreply.github.com> Date: Sun, 30 Oct 2022 23:22:13 +0530 Subject: [PATCH 1/2] Create name-ascii.py Here when the name is provided (string) will be giving an output in ASCII format. I have commented on each step and provided a demo sample for a clear understanding. --- Dev/name-ascii.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Dev/name-ascii.py diff --git a/Dev/name-ascii.py b/Dev/name-ascii.py new file mode 100644 index 0000000..b9a9caa --- /dev/null +++ b/Dev/name-ascii.py @@ -0,0 +1,22 @@ +# Python3 code to demonstrate working of +# Convert String list to ascii values +# using list comprehension + ord() + +# initializing the list +test_list = ['welcome', 'to', 'hacktoberfest'] + +# printing the original list for clear identification +print("The original list : " + str(test_list)) + +# Convertion starts here +# used ord() +res = [ord(ele) for sub in test_list for ele in sub] + +# Final out put will be provided by this code +print("The ascii list is : " + str(res)) + +########################################### +##### O u t p u t s a m p l e ##### +# The original list : ['welcome', 'to', 'hacktoberfest'] +# The ascii list is : [119, 101, 108, 99, 111, 109, 101, 116, 111, 104, 97, 99, 107, 116, 111, 98, 101, 114, 102, 101, 115, 116] +########################################### From 6a0eb7952a741fd45af6bad46d319b124e5f51c4 Mon Sep 17 00:00:00 2001 From: Heyyayaya <116991476+Heyyayaya@users.noreply.github.com> Date: Mon, 31 Oct 2022 00:57:08 +0530 Subject: [PATCH 2/2] Create word_counter.py Here, when a sentence is provided to the program, it will give how many words are there in that sentence (word count). I have used descriptive comments as well as a sample output for reference. --- Dev/word_counter.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Dev/word_counter.py diff --git a/Dev/word_counter.py b/Dev/word_counter.py new file mode 100644 index 0000000..318e691 --- /dev/null +++ b/Dev/word_counter.py @@ -0,0 +1,19 @@ +# L E T S C O U N T W O R D S O N A S E N T E N C E # + +# string initializing is in here +test_string = "Have a wonderful day!" + +# Returning the original sentence +print ("The original string is : " + test_string) + +# Counting the words begins here... +res = test_string.count(" ")+1 + +# printing Output +print ("The number of words in string are : " + str(res)) + +############################################################### +#### below is a sample demonstration of above code snippet #### +# The original string is : Have a wonderful day! +# The number of words in string are : 4 +###############################################################