Skip to content

Instantly share code, notes, and snippets.

@shinysu
Last active November 2, 2020 08:20
Show Gist options
  • Save shinysu/cc6f86953ebc1e72905448c8f3ee534b to your computer and use it in GitHub Desktop.
Save shinysu/cc6f86953ebc1e72905448c8f3ee534b to your computer and use it in GitHub Desktop.
Programs on strings
'''
program that concatinates all letters in prefixes to the suffix
'''
prefixes = 'JKLMNOPQ'
sufix = 'ack'
for letter in prefixes:
print(letter + sufix)
"""
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))
'''
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)
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)
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)
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