Entering integer variables with character symbols like ^ in the same line in python

Hello, I want to enter integer variables with character symbols in the same line in this way:
2^150 3^100 like that
How can I do that in python?
Many thanks in advance!!

What do you want to do with the special characters? Ignore them?

Hello Aslan,

You asked how to enter “integer variables with character symbols in the
same line” like this example:

2^150 3^100

shrug

I don’t know. What is the meaning of those character symbols “^” and
" " (space)?

What result is that supposed to be? Is that meant to be two numbers 2150
and 3100, or a single number 21503100, or four numbers 2, 150, 3 and
100, or something else?

If you don’t tell us what result you expect, you force us to guess, and
I don’t like guessing because for every way to guess correctly, there
are a million ways to guess wrong.

Could there be other character symbols apart from ^ and spaces?

$1 2d 3e4 5+6 x7 b8c 9!

Why do they have to be on the same line? Are you reading from a file, or
is this going to be typed into your program?

Thinking some more, I’m going to make a guess what Aslan is requesting.

How about this:

>>> a, b, c = 2**4, 3**4, 5**4
>>> print(a, b, c)
16 81 625

Is that the result you were asking? If not, I have no ideas left for
what you might want.

Hello Steven, https://www.e-olymp.com/en/contests/19075/problems/204117 in this problem I dont know how to enter input values I actually tried to use a,b,c,d = map(int,input().split())
Is there any alternative code for that?

That page requires a login. Would it be hard to cut/paste the text of
the problem into this discussion?

Cheers,
Cameron Simpson cs@cskk.id.au

Sorry, you need an account to log in to view the problem. Can you
summarise it?

You tried:

a,b,c,d = map(int, input().split())

Assuming that the user enters a space-separated string of exactly four
numeric strings, like:

12 13 14 15

then you can try this:

a, b, c, d = list(map(int, input().split()))

But if the user includes characters like “^” I don’t know what you
expect to happen.

Thank you for the response, I got it

Do you have any mobile phone number for whatsapp ? because there is a task in link. But I cannot send link because this website ignores.

Massive Numbers

The number is called massive if it is represented in the form a ^ n , which means a raised in power n . You need to compare two massive numbers ab and cd , written in the form " base ^ exponent ".

Given two massive numbers, print the biggest one.

Input

Two massive numbers a and b in the form " base ^ exponent " ( 1base , exponent1000 ). It is known that the values of a and b are different.

Output

Print the biggest number among a and b .

Input example #1

3^100 2^150

Output example #1

3^100

Input example #2

1^1000 2^1

Output example #2

2^1

Massive Numbers

The number is called massive if it is represented in the form a ^ n , which means a raised in power n . You need to compare two massive numbers ab and cd , written in the form " base ^ exponent ".

Given two massive numbers, print the biggest one.

Input

Two massive numbers a and b in the form " base ^ exponent " ( 1base , exponent1000 ). It is known that the values of a and b are different.

Output

Print the biggest number among a and b .
Input example #1

3^100 2^150

Output example #1

3^100

Hi Aslan,

The problem has to be divided into three parts:

(1) Take a string of the form “123^456” and turn it into two numbers 123

and 456.

(2) Given two such pairs from above, decide which is bigger.

(3) Print the bigger value.

The first part is the simplest. Take your string and split it at the

“^” character, then convert each part into an integer:

s = "2847^1349"

base, exponent = s.split("^")

base = int(base)

exponent = int(exponent)

Even though the puzzle uses “^” for powers (exponentiation), Python uses

the ** operator:

>>> 5**3  # 5*5*5

125

Python can make some really big numbers almost instantly:

x = 96071838452**3207

computes almost instantly on my computer, with no visible delay. On the

other hand, printing x takes a long time: it has more than 35 thousand

digits. So don’t print the value unless you have time to spare.

So to compare the two pairs, just compute the powers and compare:

x = base1**exponent1

y = base2**exponent2



if x < y:

    print(base2, '^', exponent2)

elif x > y:

    print(base1, '^', exponent1)

else:

    print("equal")

There is a catch. Although Python can compute 35-thousand digit numbers

very quickly, what if the numbers are even bigger?

What if the base has a million digits and the power is huge? Eventually

the numbers are so big that you will run out of memory and the

computation will either take a very long time, or will fail.

Ok.

You can request a line of text using the input() function. That gets you
a string.

It looks like they expect both numbers on the same line, so call input
just once to get the line of text, eg:

line = input("Enter 2 massive numbers: ")

The variable “line” will now hold a string with the text.

Strings have various utility methods. You could strip() the line to
remove leading and trailing whitespace, then split() the result to break
it into “words”, meaning here just “nonspace” text.

The split method takes an optional separator, so you could split each
“word” on the exponent character, getting two numeric strings. Calling
int() on each of those gets you the integer value of each.

In Python, the “^” character is not exponentiation. The exponentiation
operator is “**”. So you can compute the actual massive value using that
operator; Pythin ints are “bignums”, meaning they can be as large as you
like (subject to your computer’s memory), so that will be pretty safe.

Then you can just compare the two values to determine which is bigger.
or you could be clever and use Python’s max() function.

Dig around in the docs for details at:

https://docs.python/org/3/

Note both the table of contents and also the index, which is very handy
for finding arbitrary things including the operators like “**” and
methods like “split”.

Cheers,
Cameron Simpson cs@cskk.id.au

Thank you very much now I understood clearly.