# Math πrate has been successful with the Numbers quest and is extremely thankful to you
# Next he has to take up the quest with strings
# Are you ready to help him?
'''Task 1: Get Looping '''
print("**** Task 1: ****")
print()
# Math πrate is in the next step of the quest, where using a for loop, he needs to print out each individual character in a string.
# As a trial, he has to run the program given below, analyze and then take up the next set of tasks.
# Ready to help him?
# Uncomment the statements below and click on Run
text = "Looping"
for c in text:
print(c,end=",")
# What exactly happened in the program?
# The instruction was as simple as “for each character c in the variable text, print c“
# For loops can iterate over a string, just like it does with numbers
# Try changing “Looping” into any other word in the program and try
# If you notice, the characters are being displayed, one below the other.
# What if you want to display the characters, next to each other separated by a comma like:
# L,o,o,p,i,n,g
# For this all you need to do is add the following code in the print # statement like:
# print(c,end=",")
# Make this change in the program and run it.
# Did you get the output?
'''Task 2: Character Delimiter '''
print("\n**** Task 2: ****")
print()
# Math πrate is really enjoying his quest
# Now he has to uncomment the statements below and analyze the output
print("**** Your Challenge *****")
name=input("Enter your name: ")
for c in name:
print(c,end="@")
print(c)
'''Task 3: Find me if you can '''
print("**** Task 3: ****")
print()
# Have you worked with MS-Word?
# If you have to find a word in a MS-Word document, which menu option would you use?
# Lets try that in Python
# Write a program that takes the following input from the user:
# Any word, for example, plant
# A character to search in the word
# The program needs to display the number of occurrences of the character searched for. [Hint: Use a counter variable]
# Now try the program by inputting a sentence and then searching for a character
# Did it work?
def count_character():
word = input("Enter any word or sentence: ")
char = input("Enter the character to search for: ")
count = 0
for c in word:
if c == char:
count += 1
print(f"\nThe character '{char}' appears {count} times in your input.")
count_character()
'''Task 4: You’ve got a mail '''
print("**** Task 4: ****")
print()
# Math πrate cracked the previous quest with your help He now has to write a program that asks the user to enter the email address for a promotional fun event
# The program needs to check if the email address entered is valid.[Hint: check if the user has used the character “@” only once]
def validate_email():
email = input("Enter your email address for the promotional event: ")
if email.count("@") == 1:
print("Valid email address.")
else:
print("Invalid email address. The '@' character must be used exactly once.")
validate_email()
'''Task 5: What's in a name '''
print("**** Task 5: ****")
print()
# Math πrate has to write a program that accepts a username and email address.
# The user name entered should have either “$” or ”#” character. If not, an error message should be displayed
# If the user name entered is valid, only then can the user enter the email address
def registration():
username = input("Enter your username: ")
if "$" in username or "#" in username:
email = input("Enter your email address: ")
print("Registration successful.")
else:
print("Error: Username must contain either '$' or '#' character.")
registration()
'''Awesome work with the strings. You are now comfortable using the for loop with numbers and strings.'''
To embed this project on your website, copy the following code and paste it into your website's HTML: