I used a while loop to continue asking the user for a password, with the condition being the boolean locked. This loop will repeat until locked is no longer True (when the password has been entered and locked is False).
Whenever attempting to solve a computing problem I've always found it very useful to first write out what the program does in bullet points in comments. So for example for the rock paper scissors game, I would write out the steps like this:
# Ask the player for their name# Ask the player to choose either rock, paper or scissors# Randomly assign a second variable for the computer for either rock, paper or scissors# Compare the player's choice and the computer's choice and determine who won
Starting with this allows you to translate what you want the computer to do into code very easily, instead of being overwhelmed by the code.
I hope this helps. Please let me know if you have any further questions.
myFile = open("example.txt", "r") # open a text file with reading modemyList = [] # initializing an empty array for the numbersfor _ in range(6): # 6 numbers to be read number = myFile.readline() # reads a single line from the text file myList.append(int(number)) #appends the number to a list as an intprint(myList) # displays the listaverage = sum(myList)/len(myList) # calculating average of numbers in the list (len() returns how many numbers are in the list)
I hope this helps! Please let me know if you have any further questions.
Could you please send me a picture of Challenge 38, so I can see what it is asking for?
With regards to the code you've posted, it seems you want to define a variable called mylist which holds 6 numbers entered by the user. There are many different ways to do this but here is the simplest one I could come up with:
It appends to an array 6 times, asking a user for a number and converting it to an int from a string and appending it to the array mylist.
print("Please enter 6 numbers of your choice.")mylist = []for i in range(6): number = int(input()) mylist.append(number)print(mylist)
When you assigned the variables countryOne and countryTwo you assigned them as floats instead of strings, which would cause an error if you tried to enter any letters. Instead you can just leave it as this:
countryOne = input("Please enter your first country")countryTwo = input("Please enter your second country")
The strings in the dictionary are case sensitive, so you have to make sure you have entered country names exactly as how you have typed them in the dictionary.
Also, I noticed that you used quotation marks for the population of each country in the dictionary. This would cause python to recognize each variable as a string instead of an integer and perform a concatenate operation instead of an addition operation, so 127000000 + 81000000 would produce 12700000081000000 instead of 208000000.
To get around this you can simply remove the quotation marks from the numbers in the dictionary or convert them to integers before adding them (using int()):
That's what we are here for :) Apologies, we just saw a bunch of pictures and thought that you wanted us to do it all for you - we've had that before :)
How about you we go through them one at a time. Any time you get stuck, feel free to just post here :). Or if you need a little explanation of how to start, let us know - we are here for you!
Hey @EM, thanks for the post. It looks like, however, that you want us to do all of your homework for you. Unfortunately, that isn't what we are here for. We want you to learn so that way you can grow and become a more proficient individual. But, we still want to help you. :)
So, what we propose is for you to try to complete each challenge. If you get stuck, post what you are struggling with here, and we can guide you along and give you some tips/pointers. I think that is a much better solution as then you will learn what to do and every single task will become so much easier - at the end of the day, we can't sit your exam for you!
Thank you again for posting and we hope to see you soon on OnlyPhysics :))
Solution to the second question:
I used a while loop to continue asking the user for a password, with the condition being the boolean locked. This loop will repeat until locked is no longer True (when the password has been entered and locked is False).
Hi, For challenge 31 I seem to be struggling on how to exactly structure my code.
I understand that I need to place a line of code for the user to input their name but I don't understand the rest of it.
Could somebody please help me ?
Thank you!
Hello ,
please find attached : Challenge 38.
Ah, I see that makes sense .
The challenge should have been attached above - ill double check and let you know if I see it. If not I can repost it for you.
Thanks
Hello,
I have started this code for a challenge.
I am really confused with the other parts it is asking .
If you could give an explanation of how to do it that would be great and then I could complete the code.
# For Challenge 37 -> Country Populations
countryPop = {"Japan":"127000000","Germany":"81000000","Iran":"77000000",
"Uk":"64000000","Canada":"33000000","Astralia":"23000000","USA":"317000000","Bulgaria":"7000000","Sweden":"10000000"}
countryOne = float(input("Please enter your first country"))
countryTwo = float(input("Please enter your second country"))
ans = (countryOne + countryTwo)
countryOne = ""
while countryOne not in countryPop:
countryOne = input("Enter the name of the first country:")
print("Sorry can't find that information.Please try again")
print("I've found the information for you.The population of",countryOne, "is:",countryPop[countryOne],"\n")
Hi ,
this is the code I have started off but it isnt working for me. The part that I am finding hard is how to allow the user to choose the country.
I have attached my solution to the first problem. Please let me know whether you have any further questions, before we move onto the next problem.
I didn’t really want the answers but maybe an explanation one at a time . It’s fine though I just wanted to utilise the site for help. 😅
Superb!
Hey @EM, thanks for the post. It looks like, however, that you want us to do all of your homework for you. Unfortunately, that isn't what we are here for. We want you to learn so that way you can grow and become a more proficient individual. But, we still want to help you. :)
So, what we propose is for you to try to complete each challenge. If you get stuck, post what you are struggling with here, and we can guide you along and give you some tips/pointers. I think that is a much better solution as then you will learn what to do and every single task will become so much easier - at the end of the day, we can't sit your exam for you!
Thank you again for posting and we hope to see you soon on OnlyPhysics :))