0

i'm doing school project which is calculator of complex numbers. I wrote a function to calculate it but i dont know how to slice input string to make single arguments from it.

It looks like this:

in1: [complex(1.0, 1.0), complex(1.0, 1.0), ’*’, False, ’nazwa’]

in2: [complex(1 , 1), 2, ’+’, True, ’test’]

Its first number, second, operation, and two other arguments. I would like to slice it like:enter code here

number1 = 1.0,1.0
number2 = 1.0,1.0
operation = *

and 2 others. I tried input().split() but it splits it like this : [(complex(1.0 | 1.0) | '*' etc.

1
  • 2
    Input is a list, Right? why do you need to split it? just access it using index. Commented Mar 23, 2018 at 21:22

2 Answers 2

1
input1 = [complex(1.0, 1.0), complex(1.0, 1.0), '*', False, 'nazwa']
number1 = input1[0]
number2 = input1[1]
noperation = input1[2]

etc

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks mate, i didn't know it was so simple :) I tried couple times input().split() and it didn't worked for me :D
okey, it works if I write it like this but I want to have it that I can input multiple strings myself by function input() or something
0

You can use, input1[index] = input("Your message here") You can also cast the input too into the primitive type you want, such as, input1[index] = int(input("Your message here"))

2 Comments

Welcome to SO! Can you expand your answer to include a properly formatted code sample and perhaps a link to the relevant documentation?
def CKalkulator(number1, number2, operation, ifplot, name): liczba1 = number1 liczba2 = number2 znak = operation graf = ifplot if znak == '+': wynik = liczba1 + liczba2 elif znak == '-': wynik = liczba1 - liczba2 elif znak == '*': wynik = liczba1 * liczba2 elif znak == '/': wynik = liczba1 / liczba2 This function also is making plot with matplotlib and other operations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.