I am currently working on a program that takes in user inputs, and depending on that users input the string should change. I was wondering if there was a way I could alter the string once the user input has been received. The following is a sample code.
title = input('Title: ')
subtitle = input('Subtitle: ')
chapter = input('Chapter: ')
subchapter = input('Subchapter: ')
title1 = '/title{}'.format(title)
subtitle1 = '/subtitle{}'.format(subtitle)
chapter1 = '/chapter{}'.format(chapter)
subchapter1 = '/subchapter{}'.format(subchapter)
output_txt = title1+subtitle1+chapter1+subchapter1
print(output_txt)
- Input taken by user: Should be a number
- The input would then be formatted to its perspective string
- Based on the user input the string, output_txt, should be formatted accordingly
Scenario 1: User Input
Title: 4
Subtitle:
Chapter: 12
Subchapter: 1
output_txt should be
output_txt = '/title4/chapter12/subchapter1'
Scenario 2: User Input
Title: 9
Subtitle:
Chapter: 2
Subchapter:
output_txt should be
output_txt = '/title9/chapter2'
I have been using if elif but since there could be multiple combinations I do not think doing it that way is the most efficient.
Any help or tips in the right direction is greatly appreciated