Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import string
- oppgavenavn = string.ascii_lowercase # tekststreng med alle små bokstaver
- oppgavenr = 0
- while oppgavenr < len(oppgavenavn):
- x = random.randint(-40,40)
- v1 = random.randint(-40,40)
- v2 = random.randint(-40,40)
- v3 = random.randint(-40,40)
- v4 = random.randint(-40,40)
- v5 = random.randint(-40,40)
- vs = "v1*x + v2"
- hs = "v3"
- # Eksempel på vanskeligere oppgaver
- #vs = "v1/(v2*x)+v3"
- #hs = "v4/v5"
- if x != 0 and v1 != 0 and v2 != 0 and v3 != 0 and v4 != 0 and v5 != 0 and v1 != v5 and eval(vs) == eval(hs):
- out = vs + " = " + hs
- out = out.replace("v1",str(v1))\
- .replace("v2",str(v2))\
- .replace("v3",str(v3))\
- .replace("v4",str(v4))\
- .replace("v5",str(v5))\
- .replace("*","")\
- .replace("1x","x")\
- .replace("- -","+ ")\
- .replace("+ -","- ")\
- .replace("--","+")\
- .replace("+-","-")\
- .replace("(","")\
- .replace(")","")
- print(oppgavenavn[oppgavenr],") ",out,sep="",end="\t")
- oppgavenr += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement