Understanding void functions [closed] - python-3.x

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 1 year ago.
Improve this question
Write a program named program52.py that uses main and a void function named numbers that takes no arguments and does not return anything. The numbers function generates 5 random integers, each greater than 10 and less than 30 (duplicates are okay), and prints them all on one line separated by spaces. A loop is required for this, and the loop should also total up the integers so the sum can be displayed when the loop ends. The main function should call the numbers function.
This is the requirements for them, I'm very new and I've had a great deal of trouble using void functions so as you might imagine this has been difficult. I was wondering if anyone had insight on how to do this, I would not like the solution I want to understand how to do it properly.

In python, you don't need to define something to return for your function. It is by default void unless you add a return statement.
Refer to these for how to make functions:
https://www.w3schools.com/python/python_functions.asp, https://realpython.com/python-main-function/
Additionnal sources to help in your work:
https://www.w3schools.com/python/python_for_loops.asp,
https://www.techbeamers.com/python-random-number-tutorial/
You can quickly find answers to this type of question by looking it up on many websites like: W3Schools, GeeksForGeeks, RealPython and many others.

Related

Words for "pre"/"post" or "before"/"after" that sort the same logically and alphabetically? [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 2 years ago.
Improve this question
TL;DR - Silly OCD question looking for better words.
I have a list of callback labels similar to:
ingest_before
ingest_after
pre_parse
post_parse
before_notify
after_notify
This is all well and good...those names convey the context succinctly and accurately.
BUT! It bugs me that "pre" sorts after "post" alphabetically, and that "before" comes after "after" when sorted.
Note - I'm not looking to control the order my callbacks are called in this way. Their callback points are hard-coded and never sorted. I would just feel better if they sorted better when I report events or write documentation if they sorted better. I'm not interested in all the reasons why depending on this ordering is a bad idea. This is not to satisfy any sort of system requirements...just my own hangups.
So the real question is:
What is a pair of words that indicates a relative sequence between two things, that just happens to alphabetically sort in the same order?
What about First/Last, First/Then, Begin/End, Start/Stop? Are initial numbers allowed, then 1st/2nd/3rd/last. You can also make any of your pairs sort the way you want if you allow case to differ, e.g. in ASCII and Unicode, Before < after, Pre < post.

Searching for simple problems naturally solved using stacks [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 5 years ago.
Improve this question
I would like to know about simple problems that can be naturally solved using stacks with the usual interface (emptyS, isEmptyS, push, pop, top).
The complexity asociated to the context of the problem should be null. I can't touch topics like parsing, compiling or search algorithms at this moment. This discards many classical examples.
The most beautiful example I found so far is checking for balanced parenthesis in strings. In very few lines, without any other background, the exercise shows the utility of the data structure:
Another good example is procesing a string where the asterisk means to pop an item from the stack and a letter means to push it into the stack. The function must return the stack after the operations described in the string are applied to an empty stack.
If you can share some others problems, I will apreciate it very much.
Thank you in advance.
Though this question is too broad, I am going to give some other applications. Some of other common applications are -
Parsing
Recursive Function
Calling Function
Expression Evaluation
Expression Conversion
Infix to Postfix
Infix to Prefix
Postfix to Infix
Prefix to Infix
Towers of Hanoi
Some details can be found here.

use ternary operator to solve multiple conditions [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
Can anyone please help me to solve this question. it doesn't work.
Take a look here:
class Question05
{
public static void main(String[] args)
{
double gpa = Double.parseDouble(args[0]);
String res = gpa >= 3.6?"First class Hons":(gpa<3.6 && gpa>=3.4?"Upper Second Class Hons": (gpa<3.4 && gpa>=3.0?"Lower Second Class Hons": (gpa<3.0 && gpa>=2.0?"Pass":"you have failed")));
System.out.println(res);
}
}
Edit: #veena, you were trying to assign a string to gpa, which was declared as a double!!!
I had this question before, and there are a few ways, depending on what you mean with the question...
As it does appear to be a class assignment, I will give my own examples rather than fix yours.
Scenario 1:
If you would like to have multiple passing conditions, consider the following...
Surround the conditions in parenthesis, just to be safe, and use logical separators.
eg:
(1==1 && 2==2)?"yay":"sadness"
https://jsfiddle.net/o4nu3ya5/
Scenario 2:
If you want to have conditions verified based on previous condintions verified, consider the following...
Just place a ternary within a ternary, possibly called a nested ternary??
eg:
1==1?2==2?"sweet":"almost":"not close"
https://jsfiddle.net/o4nu3ya5/1/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
Ternary are super fun. Get use to them, though understand, they will frustrate a lot of fellow developers as they are harder to read.

How to create a random pair in haskell [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Hi all I am trying to create a random pairs of the specific number of mines in my minessweeper game.
so I need to make method that takes a mines number, (width,hight) and returns a list of random positions [(x,y)]
https://www.fpcomplete.com/school/starting-with-haskell/libraries-and-frameworks/randoms
This should help. Basically just use the System.Random module (https://hackage.haskell.org/package/random-1.1/docs/System-Random.html)

Effects of sound multiplication [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
What are the effects of multiplication of two different sound? An neither of them are constant, like two different songs, or one track of instrumental and one of vocals.
A simple Google search came up with this:
http://crca.ucsd.edu/~msp/techniques/v0.11/book-html/node77.html
Did you search for it at all?
But basically what happens is you end up creating an envelope where the second acts as a "coefficient" of sorts.
You also end up with a reduction of sound levels (since a decimal times a decimal is less both of them), so you'll need to amplify the signal a bit to retain volume.
The page I linked gives a lot more explanation and has a lot of the algebra needed to write up a code to implement it. Look there if you have any more questions.

Resources