Python Forum
Having issues with a lab
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having issues with a lab
#1
Question: I am currently having an issue with a lab in my class and am looking for help setting up my program. The professor asked us to make it "idiot proof" which is requiring more coding but I've hit a wall and have no idea where to move forward. Im posting the entire lab with what I have wrote so far.
I appreciate the help!
Lab Code:
"""
Program: Lab6
Author: Charles Thompson
Date: 10/6/2017
Description: The purpose of this program is to allow a user
to enter a string and to enter different commands
that can be applied to the string.
The user input can be:
x Prompt the user for a new value for strX
l Return the length of the string in strX
s Prompt user for a subscript number and display the letter at that subscript
p Prompt user for start and ending portion of strX to display
i Prompt user for the string to use to test if it is in strX
q Quit the program


Project 6 Lab Assignment is to complete this program and
issue a warning if a user tries to perform an operation that
is invalid.

(Note: You must include your analysis and design below.)

=============
ANALYSIS
=============
Input: User selected option(s) (see above)

Output: Result of applying user requested option

Calculations: (See above)
=============
DESIGN
=============
1.Initialize loop control variable (set code = 'z')
2.While code is not equal to 'q'
a. Ask user for operation code.
b. If code is equal to 'x'
b1. Ask user for Strx value
c. If code is a valid operator
c1.Calculate result
c2.Display result
"""


# Initialize messages and prompts
instructions = "This program allows you to enter a string and then interrogate the content of the string"
prompt = "Please enter x, l, s, p, i, or q to quit "
strX = "String X"
code = " "

# Display Instructions
print(instructions)

# Allow user to enter input until they are finished




# Exit the program
print("Thank you for using this program")

#Allow user to enter input until they are finished
while code != 1:
code = input(prompt)
if code == 'x' :
strx = input('Please enter a value for strx:')
elif code == 'l' :
print('Length =', len(strx))
elif code == 's' :
sub = int(input('Enter subscript'))
subr = len(strx)
if sub < subr:
print('Subscript', strx)
else:
print('Please enter a valid input')
elif code == 'P' :
Start = int(input('Enter start:'))
End = int(input('Enter ending:'))
print('Portion =',strX[start:end])
elif code == 'p' :
start = int(input('Enter start:'))
end = int(input('Enter ending:'))
print('Portion =',strx[start:end])
elif code == 'I' :
Test = input('Enter string to test:')
print('In result =', test in strX)
elif code == 'i' :
test = input('Enter string to test:')
print('In result =', test in strx)
elif code == 'q' :
code = 1
print('exiting program')
else :
print('invalid code')
Reply


Forum Jump:

User Panel Messages

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