๐Ÿ”’ Closed Para sa pyhton programmer help naman

Status
Not open for further replies.

Migzjr025

Leecher
The first input is any series of random 9 arithmetic operators.

Then input 10 numbers separated by โ€œ;โ€

Then perform the computation.

Not allowed to use the loop and conditional statements, just simple function, string, and arithmetic operators.

Assuming that the first input is strictly 9 arithmetic operators;

The second input is strictly 10 values separated by โ€œ;โ€ ; and

The result should be in the same format as in the sample output.

image.webp
 
Python:
# operators = '+/*%-++/-'
# numbers = '1;2;3;4;5;6;7;8;9;10'

operators = input('Enter 9 random arithmetic op: ')
numbers = input('Enter 10 values separated by semicolon (;): ')

zipped = zip(numbers.split(';'), list(operators + ' '))

result = ''.join([num for op in zipped for num in op])

print(f'\nThe result of {result} is: {eval(result)}')

OUTPUT:
The result of 1+2/3*4%5-6+7+8/9-10  is: -4.444444444444445

ps. sakto wala akong ginagawa kaya sinagot ko nalang haha pero next time lagay karin ng input mo kahit may error
 
Python:
# operators = '+/*%-++/-'
# numbers = '1;2;3;4;5;6;7;8;9;10'

operators = input('Enter 9 random arithmetic op: ')
numbers = input('Enter 10 values separated by semicolon (;): ')

zipped = zip(numbers.split(';'), list(operators + ' '))

result = ''.join([num for op in zipped for num in op])

print(f'\nThe result of {result} is: {eval(result)}')

OUTPUT:
The result of 1+2/3*4%5-6+7+8/9-10  is: -4.444444444444445

ps. sakto wala akong ginagawa kaya sinagot ko nalang haha pero next time lagay karin ng input mo kahit may error
grabe naman yung syntax mo subrang concise
i mean yung beauty ni python ๐Ÿ˜… (yung one liner)


parang mahirap sa beginner๐Ÿ˜‚
 
grabe naman yung syntax mo subrang concise
i mean yung beauty ni python ๐Ÿ˜… (yung one liner)


parang mahirap sa beginner๐Ÿ˜‚
Haha yan lang nasa isip kong magawa boss eh.
Bawal daw kasi for loop and conditional statement =D
Explain ko nalang sa kanya if maguguluhan siya
 
Status
Not open for further replies.

About this Thread

  • 7
    Replies
  • 1K
    Views
  • 5
    Participants
Last reply from:
arj21

Online now

Members online
647
Guests online
909
Total visitors
1,556

Forum statistics

Threads
2,277,904
Posts
28,979,570
Members
1,229,144
Latest member
Karisma18
Back
Top