Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fix this?
#1
Hi.
So, my question is:
When I ran the below code all values change to custom(as it should be), except for the last phrase. I wonder if anyone has advice on how to fix it? Any advice would be very appreciated. Thanks

first_name = str (input("first name:"))
sender_name = str (input("sender name:"))
friend_name = str (input("friend name:"))
#text first version
text1 = '''Dear first_name!
How are you? Everything is okay with me. I miss you! Have you seen friend_name? If so, please, tell him/her to call me. By the way congratulations on your age birthday! Some phrase regardingage.
Yours sincerely,
sender_name'''
birt_year = int(input("birth year:"))
year = 2022
some_age_phrase = str("")
is_M = bool
age = year - birt_year
age = str(age)
error = "are you joking"
#replacing name to input name
a = text1.replace('first_name',first_name)
b = a.replace('friend_name',friend_name)
c = b.replace('age',age)
d = c.replace('sender_name',sender_name)
#replacing friend gender to input gender
#checking and replacing gender, error explanation to a user
try:
    friend_gender = int(input("0- male 1- female:"))
    if friend_gender == 0:
        is_M = True
        is_M = 'him'
        e = d.replace('him/her',is_M)
        print(e)
    elif friend_gender == 1:
        is_M= False
        is_M ='her'
        e = d.replace('him/her',is_M)
        print(e)
    else:
        print("No such gender supported")
except ValueError:
    print("Only numbers! 0 or 1")

if 0 <= int(age) <= 17 :
     e.replace ("Some phrase regardingage","Next year you'll be")
elif  18 <= int(age) <= 60:
    e.replace ("Some phrase regardingage",'You can vote now')
elif  60 <= int(age) <= 110:
    e.replace ("Some phrase regardingage", " Hope you do not get bored on your retirement!")
else:
    print(error)
This is my output:
Output:
first name:Mike sender name:Ann friend name:Amy birth year:2013 0- male 1- female:1 Dear Mike! How are you? Everything is okay with me. I miss you! Have you seen Amy? If so, please, tell her to call me. By the way congratulations on your 9 birthday! Some phrase regarding9. Yours sincerely, Ann
Larz60+ write May-13-2022, 10:39 PM:
Double post see: Posts to NOT make at all
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020