Python code that does subtracting and adding? [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am new to learning python, I see it's a simple language but my teacher thinks it's a good thing to give me very advanced tasks to complete, I have it due tomorrow so if anyone could manage to code this in, I will be greatly appreciated. Here is what he wants:
Detect user input for the words: "add" and "sub" aka subtraction. if the wrong answer is given, it should re-ask the question.
If the user chooses either, it should generate two numbers from 1-9, number 1 >= number 2, and the user should be asked the answer.
If the answer is correct, it should move to the next round (our teacher said there must be 5 rounds, at each end of the round the code should ask the user to type "add" or "sub" again.
if the user gives the wrong answer, it should re-ask the question.
The code ends when all 5 rounds are done, or if the user types "end" at any time with a message saying "Goodbye".
Greatly appreciated.

It is generally uncalled for people to post their homework here and have it solved, as StackOverflow is meant as a place that every question can help out a lot of people interested in your matter.
While I will not do your homework, here's what you can do:
Use "while" statements for the input check and validation, which means it will keep asking if the input is different from the value you set as required for the loop to break.
Use "If" statements for general validation checks.
What is most important though is that you take the time and read/watch tutorials that can help you get a better understanding of the language, as Stackoverflow is a place for questions of a specific nature and not a homework-solving/debugging service. Hope I could be of help!
I personally recommend the following resources for learning Python:
https://www.mikedane.com/
https://www.w3schools.com/
https://www.sololearn.com/
Personal Playlist for learning Python

Related

School project while and for loops need some tips [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
This post was edited and submitted for review 2 days ago.
Improve this question
So I have this assignment for school, so I don't want an answer just given to me if possible, but rather steered towards the right direction. Basically we've been working with while and for loops along with if, else and elif statements. We also learned about using the break command.[[enter image description here]picture of the assignment
I have put the images of the code and the assignment in here, my problem is I have the first part here but then when I move the first break statement, it just loops since it isn't under the while loop, but when i move it under the while loop, the second for loop sees the 75, and thinks it needs to be in the second loop and doesn't execute.
while True:
if choice == 1:
for a in range(200,70,-5):
print(a, end = ' ')
if a == 75:
break
while True:
if choice == 2:
for b in range(3,130,7):
print(b, end = ' ')
if b >= 129:
break
As pointed out by #Michael, it would be better if you could share your explicit code. There are code brackets that you can use for this, that enable you to have clean formatting in your message.
Anyways, I noticed that you might have some indentation issues, the 4th line that contains a print-statement seems a little far in, and shouldn't even run. Considering the validation steps that you are using, please consider that you can use the if-statements within the for or while loop. You are currently call break on the if-statement, but you can also use other callbacks like continue and pass. I think this article explains that nicely: https://www.guru99.com/python-break-continue-pass.html
Lastly, it might be worthwhile to install an IDE, like VS Code (this one is free). The IDE or Integrated Developer Environment can be helpful to organize and validate your code, making writing it so much easier.

Need to write a program that flashes individual words on a screen for a specific period of time each (between 100-400ms) when I click or with breaks [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed yesterday.
Improve this question
Need to write a code that lets me flash individual words from a list of words on the screen for a specific period of time each with breaks in between (for example, I click the mouse and the first word appears for 100ms, then a random letter sequence (1 minute or so), then another word for 400ms, then the same random letter sequence as before....). No coding experience, so I'm not sure where to start and what coding platform/language to use- any pointers? Thanks!!!
*Also, if anyone knows how to maybe make it so I can click to pause and start the sequence, that would be AMAZING. And being able to randomize the words to draw from a list that I provide would be amazing too... not sure if these things are possible but there are some pretty great coders on this site, so hopefully someone knows how to do this!! :)
Haven't tried anything yet... I am new to coding and would love some guidance on where to start!

Deploying python scripts [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am a python beginner and I am a little experienced in OO-programming in Java and PHP and also fucntional programming in R . Thus, my question is considering the general usage of python scripts in everyday use-cases.
I want to "learn" how to think/approach a problem that I do experience when facing a situation with my software where a "script" could help me out or improve something.
For instance, I've heard friends talking about their self-made python scripts to evenly mute the audio of movies to avoid loud outliers in explosive scenes, etc. Another example, in my case righ tnow, is to filter out certain pictures with no GPS-time meta information for the timezone in order to sort these fotos in accordance with the others.
I really want to get the essence and recipe based on the aforementioned examples to better integrate Python in my everyday life and get an intuitive feeling for it. (i.e. how would a simple script look like that takes a picture, filters out its meta data, and does something -> where do I have to run the script so I can call the function with these .JPG files as its arguments?).
I would also be glad if some of you could recommend some practical tutorials or literature.
Thank you in advance :)
P.S. I know it is not a concrete question but rather it is intended to get a glimpse on a wide field of usage and thinking - but I want to get this essential take away that motivates me and shows me the direction.

is it a good practice in python? function shortcuts? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
is it a good practice that i usually (tend to) do in python?
making shortcut of functions for example:
p = print
and the i use:
p('hello world')
or
p(2**5)
does it affect on performance? What is your suggestion, is it OK?
A good practice in Python is: easy is better. You do not give much clarity in your code by doing that (and depending on the IDE-highlighting strategy, make it even worse for others). Furthermore, the choice of your shortcut, namely p, is really a bad idea. How about people writing code with prime numbers (and P is not a good idea too).
For performances, there is no gain I think. Since print is a built-in function, you actually add a variable inside globals() or locals(). In my opinion, this is 1) not a good practice to use shortcuts like that 2) not an improvement in performance.
I have no idea if it is a good practice in python, but in general I would say no.
It will take away readability for other readers of your code. If the codebase grows large and you replace a lot of functions with very short names you make it difficult to read in general.
Coming from many years of code maintenance if I was called out in the middle of the night to fix a code problem in production and found code like that I am pretty sure I would hunt you down in the morning and ask why you would ever do such a thing.
If you are lazy and doesn't want to write so much - get your self an editor that can complete code for you instead.

Python Board Game Trouble [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
this is for a school class i am learning computer scicence and i am working on a this code and i have been having some trouble and it is very hard to understand my teacher so i was wondering if anyone would be willing to help me with this program
gridl=[]
inputO=input("Please Enter").split(",") #Input Statement 1
numberO=inputO[0]#The Number Of "O" in the Input
Ocord=inputO[1:len(inputO)]#The O's
numberO=int(numberO)
for j in range(0,len(Ocord)):
gridl.append(Ocord[j-1:j+1])
for i in range(0:len(gridl))
newgrid=[]
inputX=input("Please Enter").split(",") #Input Statement 2
numberX=inputX[0] #The Number Of "X" in the Input
Xcord=inputX[1:len(inputX)]
print (Xcord)
The Rules and instructions:
Test inputs and outputs:
This is for an assignment, and you have done nothing except try (and fail) to get the first couple of lines read in. So I'm not going to be able to help you with your code - there's no code.
Instead, here are some hints:
Don't do things piecemeal if you can avoid it. When you're reading input, read all the input. When you're parsing the input, parse all the input.
You're going to make a bunch of mistakes doing this. It would help you to be able to "see" what you're doing. So, even though it's not required, I strongly suggest you make a function that will print out your game board. That way, you'll be able to "see" the situations of the pieces.
You're going to be doing some common operations, like adding pieces and getting the value of pieces. Make functions for those actions, if you can. Raise exceptions when things go wrong. The more time you spend being strict at the bottom levels, the less stupid mistakes you allow yourself to make at the top levels.
Get your types right. According to the instructions, everything in the input and output will be a number, except for the word 'None'. So you need to make sure that your input is all converted to numbers as soon as possible.

Categories

Resources