Discussions on Python Programming: Weeks 6, 7, and 8

Verified

Added on  2023/04/07

|5
|598
|448
Homework Assignment
AI Summary
This document presents a compilation of discussions and solutions related to Python programming assignments spanning weeks 6 through 8. The content covers various topics, including the 'NameError' problem encountered while working with functions, where students explored the concept of functions, parameters, and return values. The assignment also delves into password verification, where students aim to create a function to validate passwords based on length, presence of numbers, and capital letters. Furthermore, the document addresses currency conversion using Python, exploring the use of dictionaries to convert between currencies like BGN, GBP, EUR, and USD. The discussions include student attempts at coding, error identification, and suggestions for improvement, referencing external resources and providing helpful insights into debugging and problem-solving in Python programming. This assignment is a great resource to learn more about Python programming with hands-on examples.
Document Page
DISCUSSIONS: WEEK 6-8
Name
Instructor
Institution
Course
City
Date
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Week 6: NameError problem
For this week, we went further on functions in python programming. One of the lessons
which I have learnt from function is that it is a block of code which runs only when called. Also,
I noted that one can pass data into a function which is known as parameters. I also noticed that
function can return data as well. This was my first time to use functions in python. I was trying
to create a new function but I would always get errors and I don’t not know the reason behind it.
Code
def printme (str)
print str;
return str;
printme (“My string”);
In the first place I thought that this would execute logically but I would always get an
error. The name of the error was ‘printme’ is not defined
Reply: Financial Application Redux by Mathew
Working with functions is not easy as people might think. You need to note that, when working
with main functions, a script does not import itself. Also one might misspell the initials on the
return line. Inaddition one need to note that one need to first define the main function, then
continue to set-up the windows and list attributes and invoke the main function
Reply to walker
Calling functions is very easy please go through work by W3schools the link is
https://www.w3schools.com/python/python_functions.asp
Week 7: Password verifier
Document Page
I am trying to create a python function to validate whether the password inputted by the user
contains at least one number, one capital letter, and it is ten characters long
My code is
def validate();
while True:
password = input("Enter a passcode ")
if len(passcode) < 10:
print("Make sure that your passcode is have a minimum of ten characters")
elif not passcode.isdigit():
print("Make sure that your passcode has a # in it")
elif not passcode.isupper():
print("Make sure that your passcode has a # in it")
else
print("Your passcode is fine")
break;
validate()
Am wondering what could be the problem with this code since when I run the code and enter
the password , the code keeps me “Make sure that your passcode has a # in it” really don’t know
what is the problem.
Response to Alexander Webb
Alaxander
Password verifier are best when using if else statements. With If statements you will be
able to check two or three conditions. You can use if else statement inside another if statements
if the conditions are more than three.
Reply Alex on identification
Document Page
There are two common errors with indentation which are forgetting to indent the statements of
user defined and with a compound statement.
Week 8: Currency converter
I have been running a python program which converts currencies. The currencies which I
was dealing with are BGN, GBP, EUR, and USD. I thought I could use a dictionary where IO
came up with the code
value = float(input())
in_curr = input()
out_curr = input()
dict = {'BGN': 1, 'USD': 1.79549, 'EUR': 1.95583, 'GBP': 2.53405}
def currency_converter (value,in_curr,out_curr):
return((dict[in_curr] / dict[out_curr]) * value)
The code never worked and at first I thought it is because I never used the print function but still
I got the same problem
Reply to Alaxander Webb
That was good work, but to learn how to format output in python is when one is supposed to take
control of their python statements. The pose by Martin Heroux can be of help Alex, the link s
https://scientificallysound.org/2016/10/17/python-print3/
Reply to Anthony Walker
Anthony why don’t use functions. I think you better define a function. Check this please
https://www.codecademy.com/en/forum_questions/521773f480ff33b5bf002019
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]