why does this code produces output like this but not like this?

jupyter notebook not displaying output cells
jupyter notebook not running code
jupyter notebook in[*]
write a program that asks the user for his name and greets him with his name in python
write a python program that prints (displays) your name, address, and telephone number.
jupyter notebook hide output
how to see output in jupyter notebook
jupyter notebook display full output

when I give these inputs to list:

List: 123 234 543 2 22 9
min = 123, max = 9

it returns 123 as min and 9 as a max number where as it should be 543 as max and 2 as min

while True:
    input_string = input("List: ")
    if not input_string:
            exit()
    ListArray = input_string.split()
    max_value = max(ListArray)
    min_value = min(ListArray)
    print("min = {}, max = {}" .format(min_value, max_value))

I expect the output to be 543 as max and 2 as min

Each value in Python is of a particular data type - for example, string, number, list, dictionary, objects (of various kinds), etc. They have different semantics. Let's try this:

>>> "abc" + "def"
'abcdef'
>>> 1000 + 999
1999

When you split the string input by the user into items, those items remain strings. For strings, "a" < "aa" < "b", and similarly "1" < "11" < "2" (see Lexicographical order).

To find the maximum and minimum numbers in the list, you have to convert all the individual strings:

ListArray = [int(s) for s in ListArray]

Note that if the input had anything but numbers, the program will now raise an exception.

Function in python not producing output?, So I am curious as to why I get a value displayed in the IDLE enviroment but not the code editor, when I have entered precisely the same code :(. Adding a semicolon to the end of a statement suppresses output and is a common practice. Code analysis alerts you to lines that produce output, but lack the terminating semicolon. If you want to view output from line 48, do not add the semicolon as the message suggests.

Going off of jhpratt's comment, one way that you can do this is through a list comprehension. You can change the line ListArray = input_string.split() to ListArray = [int(i) for i in input_string.split()], which will cast each of the elements in input_string.split() into an int.

If you would rather use a for loop instead of a list comprehension, you can do this:

for i in range(len(ListArray)):
    ListArray[i] = int(ListArray[i])

This should make your code do what you expect it to!

Program Examples, If you want the user to enter data into the program, you can use the input() function. It will then use the print() function to output the word that they entered. Using variables makes it easier for people to understand what is going on. if it is True and nothing if it is False; the print code is not indented, this is because it is not� First of all, on ideone you compiled this using a C++ compiler, Neither C nor C++ allows the expression p = a to compile in this program but gcc (which is likely what you&#039;re using) enables many non-portable language extensions to C by default (few

Once you get the input_string entered by the user, use list comprehension to cast each string element of input_string.split() into an int. At this point ListArray is basically a list of numbers and you can now easily calculate the minimum and maximum value.

input_string = input("Insert a list of numbers: ")
ListArray = [int(i) for i in input_string.split()]
print("min = {}, max = {}" .format(min(ListArray), max(ListArray)))

Input and output | Think Java, These methods are not easy to use; fortunately, Java provides other classes that make it easier to handle common Before you can use Scanner , you have to import it like this: Using an import statement makes your code unambiguous. Write a program that compiles and runs both in C and C++, but produces different results when compiled by C and C++ compilers. There can be many such programs, following are some of them. 1) Character literals are treated differently in C and C++.

1.10. Input and Output — Hands-on Python Tutorial for Python 3, In the hello_you.py program this value is assigned to the variable person, for use later. We do not want string concatenation, but integer addition. We need� Please make sure that you are following the output specification to the decimal point. If you have one character out of place, your submission will be marked as incorrect After reading the problem statement, you will be given a sample "Input” and the resulting expected “Output” your program should submit.

3. Output from the Common Gateway Interface, The most basic output for a CGI program is a simple document in either plain text the headers you generate from a CGI program can be output in any order you like. If you don't include the blank line after the header, the server will assume code that deserves special attention is status code 204, which produces a “no� The program and output are as follows #include<stdio.h> int main() { int x=10; printf("%d %d %d ",x,x++,x--); return 0; } Output: 10 9 10 The order of evaluation of function arguments is not defined by the language standard.

Quine (computing), A quine is a computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the � Visual Studio Code is a streamlined code editor with support for development operations like debugging, task running, and version control. It aims to provide just the tools a developer needs for a quick code-build-debug cycle and leaves more complex workflows to fuller featured IDEs, such as Visual Studio IDE .

Comments
  • You need to convert the string to a number.
  • Note that ListArray should instead be named list_array to comply with PEP-8 (Python's code-style conventions), which specifies CapWords (aka CamelCase) only for class names, not for other variables.
  • Because this doesn't explain why the old code is wrong and the new code is right, it's not as helpful as it could be in assisting the OP in not making the same mistake again in the future.