Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How can I loop this part of the code?

+2 votes
asked Aug 30, 2020 by Rohan (280 points)

Hello, this is my code in Python.

oc1 = "+"
oc2 = "-"
oc3 = "*"
oc4 = "/"
oc5 = "//"
oc6 = "%"
oc8 = "^2"
oc9 = "^3"
oc10 = "^1/2"
oc11 = "^1/3"
oc12 = "^4"
oc13 = "^1/4"
oc14 = "^5"
oc15 = "^1/5"
print("Hello, I'm Envision, your personal python assistant.")
print("Thank You for using Opaque Python Calculator\nEMAIL for inquiries : [email protected]\nJoin Opaque CC :-\nhttps://www.cognitoforms.com/Opaque1/opaqueccapplication")
s1 = "Please type the module, which will be used ( 1 or 2 ) : "
print("Available Responses : \n Addition ( + )\n Subtraction ( - )\n Multiplication ( * )\n Division ( / )\n Rounded-off Division ( // )\n Divisional Remainder ( % )\n Square ( ^2 )\n Cube ( ^3 )\n Square Root ( ^1/2 )\n Cube Root ( ^1/3 )\n Power 4 ( ^4 )\n Root 4 ( ^1/4 )\n Power 5 ( ^5 )\n Root 5 (^1/5 )")
i1 = input(s1)
if i1 == "1" :
    in1 = float(input(" "))
    in2 = input(" ")
    in3 = float(input(" "))

    if in2 == oc1 :
        op1 = in1 + in3
        print("=" , op1)
    if in2 == oc2 :
        op1 = in1 - in3
        print("=" , op1)
    if in2 == oc3 :
        op1 = in1 * in3
        print("=" , op1)
    if in2 == oc4 :
        op1 = in1 / in3
        print("=" , op1)
    if in2 == oc5 :
        op1 = in1 // in3
        print("=" , op1)
    if in2 == oc6 :
        op1 = in1 % in3
        print("=" , op1)
if i1 == "2" :
    in1 = float(input(" "))
    in2 = input(" ")
    if in2 == oc8 :
        op1 = in1 ** 2
        print("=" , op1)
    if in2 == oc9 :
        op1 = in1 ** 3
        print("=" , op1)
    if in2 == oc10 :
        op1 = in1 ** 0.5
        print("=" , op1)
    if in2 == oc11 :
        op1 = in1 ** (1/3)
        print("=" , op1)
    if in2 == oc12 :
        op1 = in1 ** 4
        print("=" , op1)
    if in2 == oc13 :
        op1 = in1 ** 0.25
        print("=" , op1)
    if in2 == oc14 :
        op1 = in1 ** 5
        print("=" , op1)
    if in2 == oc15 :
        op1 = in1 ** 0.20
        print("=" , op1)

HOW CAN I GET THE in2 AND in3 VARIABLES TO LOOP??

2 Answers

+2 votes
answered Sep 7, 2020 by 197167 Raja Reddy P (180 points)
use arrays instaed of in1 in2 in3,,

u can use in[0],in[1],in[2] etc
0 votes
answered Jun 22, 2021 by Omer Shamim VI-E-A (160 points)
You can surround them with a for loop

for variable in range (the number of times you want it to repeat)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...