Program to find greater number from given 4 values

I want to write the program without using and operator.

is this what you want

one = int(input())
two = int(input())
three =int(input())
four = int(input())
greater = max(one, two, three, four)
print(greater)

i think you need the int but im not sure…

The solution above might work, but I don’t know if it will as I do not know python.

Here’s my own manual implementation in JavaScript with an elaboration on how the code works:

Below is a function that finds the greatest number out of all the numbers in the provided array.

The variable called “greatest” will be where the greatest number in the array is stored. In the function, we will loop through the array and check if the value in the array is greater than the number set on greatest. If it is, greatest will be set to the value in the array. If not, we will continue looping through the array and setting greatest to the highest value in the array.

function getGreatestNum(array){
	let greatest = array[0];

	for(let i = 0; i < array.length; i++){
		if(array[i] > greatest){
			greatest = array[i];
		}	
	}

	return greatest;
}

const array = [1, 3, 5, 4];

// Returns 5, the greatest number in the array
console.log(getGreatestNum(array))

Above was a manual implementation. However, there is simpler way to do this instead of creating a for loop manually. You can instead use the forEach method of arrays to loop through each element instead.

Below, we took the same approachas the manual one by looping through each number in the array and checking if the looped value in the array is greater than the value set in the greatest variable. If the value is greater, greatest is set to the value.

function getGreatestNum(array){
  let greatest = array[0];

  array.forEach(value => {
	 if(value > greatest){
		greatest = value;
     }
  })

 return greatest
}

const array = [1, 3, 5, 4];
console.log(getGreatestNum(array))
// Prints 5

The difference between this implementation and that the last one is that we use a method that directly loops through the array instead of creating a for loop manually. :slightly_smiling_face:

I can confirm this works without int, better script would have prompts such as

one = int(input("First Number: "))
two = int(input("Second Number: "))
three =int(input("Third Number: "))
four = int(input("Fourth Number: "))
greater = str(max(one, two, three, four))
print("The highest number in this collection is " + greater)

If u good at python plz come help in my post about an adventure game, sent 2 hours ago plzzz

Hi @vanshika3915 !
Is this a school assignment?