Last active
November 2, 2020 08:20
-
-
Save shinysu/cc6f86953ebc1e72905448c8f3ee534b to your computer and use it in GitHub Desktop.
Programs on strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
program that concatinates all letters in prefixes to the suffix | |
''' | |
prefixes = 'JKLMNOPQ' | |
sufix = 'ack' | |
for letter in prefixes: | |
print(letter + sufix) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
function to check if substring is in the string or not | |
""" | |
def contains_substring(s, sub): | |
if sub in s: | |
return True | |
else: | |
return False | |
s = input("Enter the string: ") | |
sub = input("Enter the substring to find: ") | |
print(contains_substring(s, sub)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
split a sentence into words and print | |
''' | |
sentence = 'A quick brown fox jumped over the lazy dog' | |
print(sentence.split()) | |
for word in sentence.split(): | |
print(word) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Hello! I'm an echobot. I can repeat whatever you say") | |
while True: | |
inp = input().lower() | |
if inp == 'hi': | |
print("hello") | |
elif inp == 'bye': | |
print('Good Bye') | |
break | |
else: | |
print(inp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Hello! I'm an echobot. I can repeat whatever you say") | |
while True: | |
inp = input().lower() | |
if inp == 'hi' or inp == 'hello': | |
print("hello") | |
elif inp == 'bye' or inp == 'good bye': | |
print('Good Bye') | |
break | |
else: | |
print(inp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Hello! I'm an echobot. I can repeat whatever you say") | |
while True: | |
inp = input().lower() | |
if 'hi' in inp: | |
print("hello") | |
elif 'name' in inp: | |
print("My name is botty!") | |
elif 'bye' in inp: | |
print('Good Bye') | |
break | |
else: | |
print(inp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment