0
I am doing a program in Python, whose statement is as follows::
Create a function that takes a string and turns some of the characters into uppercase and others into lowercase.
I need the user to enter the amount of draws he wants to make, for example: If he wants to draw 3 numbers, the program will draw 3 numbers between 0 and Len(string), then the program checks whether the string in the drawn position is uppercase or minuscule, If it’s a capital case, turn it into a minuscule, and if it’s a minuscule, turn it into a capital... I made this program in C and wanted to do in python too, but I’m not getting it, I did so far: (but it’s giving error)
from random import randint
frase = str(input("Digite a String: "))
while True:
qntd_sorteio = int(input("Quantos números deseja sortear? "))
if qntd_sorteio >= 1:
break
else:
print("O número precisa ser um número real...")
pos = 0
while qntd_sorteio > 0:
pos = randint(0, len(frase))
if frase[pos].isupper():
frase[pos].lower()
elif frase[pos].islower():
frase[pos].upper()
qntd_sorteio -= 1
print(frase)
I don’t know what the mistake, I don’t know how to turn, if anyone can help me...
Don’t know what the bug is? It didn’t appear when you tried to run the code?
– Woss
Appears "Indentationerror: Unexpected indent" in the line of the "if phrase[pos]. isupper():"
– Brenno Carvalho
https://www.geeksforgeeks.org/isupper-islower-lower-upper-python-applications/
– Maury Developer
This is indentation error. Inside your
while
there is aif
indented wrong. In Python it is trivial that you properly format all lines of code.– Woss
@Maurydeveloper This he has done in his code, I did not understand what the purpose of quoting this link...
– Woss
Oh yes, sorry, that I had noticed but I had not fixed here, but the problem continues, I do the raffles and everything and when I will print the string, it printa without any changes
– Brenno Carvalho
My only problem is that the changes are not being made, they go into Ifs and Elses, but when I do the attribution, to change it to a greater or smaller size, they don’t change
– Brenno Carvalho
Error not syntax @Andersoncarloswoss https://repl.it/KnottyNanoPacket
– Maury Developer
I just need to know how I turn, for example: "Q", into "q", because the assignment I am doing is not correct...
– Brenno Carvalho