Home > Mobile >  How to have integer subtract from a string in python?
How to have integer subtract from a string in python?

Time:11-08

I'm currently working on a chatbot from scratch as an assignment for my intro to python class. In my assignment I need to have at least one "mathematical component". I cant seem to find out how to have my input integer subtract from a string.

Attached is a screen shot, My goal is to have them input how many days a week they cook at home and have that subtract from 7 automatically.

print('Hello! What is your name? ')
my_name = input ()
print('Nice to meet you '   my_name)
print('So, '   my_name   ' What is your favorite veggie?')
favorite_veggie = input ()
print('Thats nuts! '  favorite_veggie   ' is mine too!')
print('How many days a week do you have cook at home? ')
day = input ()
print('So what do you do the other '   ????? 'days?')

CodePudding user response:

You are looking for this

day = input()
required_days = 7 - int(day)
print('So what do you do the other '   str(required_days)   ' days?')

CodePudding user response:

day = int(input())
print('So what do you do the other', 7-day, 'days?')

CodePudding user response:

You may convert the result of the input to int, then do the substraction. Also input("") accepts a string as parameter, that will be shown in front of the prompt area, that makes better code

my_name = input('Hello! What is your name? ')
print('Nice to meet you '   my_name)

favorite_veggie = input('So, '   my_name   ' What is your favorite veggie?')
print('Thats nuts! '   favorite_veggie   ' is mine too!')

day = int(input('How many days a week do you have cook at home? '))
non_work_day = 7 - day
what_do = input('So what do you do the other '   str(non_work_day)   'days?')
  • Related