Overview
So, sometimes I assist people with their homework. Sometimes for fun I will pluck their homework assignment from the web and just do it. Not doing this to be mean. I genuinely help them and point them to resources after I’ve solved it using a few different code snippets.
Home work this time is someone who needs help with their Python programming assignment.
I used to do this all the time for college students in the past. Just figured I document it from now on. Perhaps it will provide some insight. Who knows.
Trying to figure out a better title for this. Current title is the best that I’ve come up with. Lets get started.
I would like to note. I have no intension of shaming anyone here. You’re learning. Read and research the code a little by reading the documentation. I will provide resources in the article within a couple of hours or so.
Assignment
Below is the assignment.
- Using
input()
obtaining 2 strings from user, and merge them together as a new string namedstr3
.- Return the length of str3.
- Turn all letters to be upper case in all strings.
- Turn all letters to be lower case in all strings.
- Attach the string “Python” to str3
Solutions
Below are a few solutions from the assignment with explaination.
Solution 1
This is the first solution that I came with. Followed the instructions to the letter with this one. The user experience is ugly and so is the code. But, it gets the job done.
Explaination on what the code does is in the commments. Comments are indicated with the
(#
) value.
"""
file: homework.py
author: Timothy (n3s0)
description:
Assisting someone with doing their homework. This is what came out of my own work completing
the assignment. Listed below are the requirements for it.
- Using ```input()``` obtaining 2 strings from user, and merge them together as a new string named ```str3```.
- Return the length of str3.
- Turn all letters to be upper case in all strings.
- Turn all letters to be lower case in all strings.
- Attach the string "Python" to str3
~
"""
# Obtain user input and assign the value to str3.
str3 = input() + input()
# print the length of both strings obtained by the user.
print("Length of the string: {}".format(len(str3)))
# print the string in upper case. Uses the .upper() method
# which converts the strings to upper case.
print("String in UPPER case: {}".format(str3.upper()))
# print the string in lower case. Uses the .lower() method
# which prints the string in lower case.
print("String in lower case: {}".format(str3.lower()))
# Concatenates Python to the end of the string. Instructions don't specify.
# They just say attach the work to the string.
print("String with 'Python' attached to it: {}".format(str3 + "Python"))
Solution 1 - Output
Below is the output for solution 1
[n3s0@test-machine 20220214230925]$ python homework.py
;ldkjfa;lfj
f;lskjf;lajf
Length of the string: 23
String in UPPER case: ;LDKJFA;LFJF;LSKJF;LAJF
String in lower case: ;ldkjfa;lfjf;lskjf;lajf
String with 'Python' attached to it: ;ldkjfa;lfjf;lskjf;lajfPython
Solution 2
Below is another solution that doesn’t follow the requirements of the assignment to the letter. But, it’s cleaner and I do like it a lot more.
"""
file: homework.py
author: Timothy (n3s0)
description:
Assisting someone with doing their homework. This is what came out of my own work completing
the assignment. Listed below are the requirements for the assignment.
- Using ```input()``` obtaining 2 strings from user, and merge them together as a new string named ```str3```.
- Return the length of str3.
- Turn all letters to be upper case in all strings.
- Turn all letters to be lower case in all strings.
- Attach the string "Python" to str3
~
"""
# Obtain input from the user and assign the value to the str1 variable.
str1 = input("Obtaining String 1 (Type in me, human): ")
# Obtain input from the user and assign the value to the str1 variable.
str2 = input("Obtaining String 2 (Type in me, human): ")
# Concatenate str1 and str1 variables and assign their value to str3.
str3 = str1 + str2
# print the length of both strings obtained by the user.
print("Length of the string:", len(str3))
# print the string in upper case. Uses the .upper() method
# which converts the strings to upper case.
print("String in UPPER case:", str3.upper())
# print the string in lower case. Uses the .lower() method
# which prints the string in lower case.
print("String in lower case:", str3.lower())
# Concatenates Python to the end of the string. Instructions don't specify.
# They just say attach the work to the string.
print("String with 'Python' attached to it: {}".format(str3 + "Python"))
Solution 2 - Ouptut
Below is the output for solution 2. Looks like it does everything that it should.
[n3s0@test-machine 20220214230925]$ python homework.py
Obtaining String 1 (Type in me, human): fdsgfdsgfdsgfdsa
Obtaining String 2 (Type in me, human): gfdsagfdsgfdsafds
Length of the string: 33
String in UPPER case: FDSGFDSGFDSGFDSAGFDSAGFDSGFDSAFDS
String in lower case: fdsgfdsgfdsgfdsagfdsagfdsgfdsafds
String with 'Python' attached to it: fdsgfdsgfdsgfdsagfdsagfdsgfdsafdsPython
Resources
Below are the resources provided for comming up with the solution to the assignment.