Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
So I want to convert strings to shapes after being given a certain string by the user.
e.g "I love squares" = square shape.
what about just looking for the word to convert to in the string? something like this:
userstring = "I love squares"
if not userstring.find('squares') == -1:
create_square()
if not userstring.find('circle') == -1:
create_circle()
#etc etc
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to check if the char in string is English alphabetic or not. I mean, the method is.alpha() will return True if I put Hebrew letter, but I want only English letter.
Check if it is letter and if it is ascii character
def isEnglish(s):
return s.isascii() and s.isalpha()
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
answer=input(print('What s the capital',country,'?'))
RETURN
What s the capital of South Africa ?
None
And I have to put my answer just after the 'none'
You are printing inside the input function and print returns None.
You should do something like this:
country = "Italy"
answer = input(f"What's the capital of {country}? ")
print(answer)
Read the documentation here.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
eg-In this instead of using 21 (a value), I want to use a variable to generalize it
print("{:-^21}".format(".|."*(2*(i+1)-1)))
I want to use something like this
print("{:-^M}".format(".|."*(2*(i+1)-1)))
That can easily enough be done. For example:
M = 40
i = 3
print("{val:-^{width}}".format(width=M, val=".|."*(2*(i+1)-1)))
Outputs:
---------.|..|..|..|..|..|..|.----------
You could also do it with f-strings (note the outer ' because " is used on the inner expression):
print(f'{".|."*(2*(i+1)-1):-^{M}}')
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to convert a tuple:
('Cobra',)
to a string, which when printed yields:
Cobra
#Assuming you have a list of tuples
sample = [('cobra',),('Cat',),('Dog',),('hello',),('Cobra',)]
#For each tuple in the list, Get the first element of each tuple
x = [i[0] for i in sample]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I took a python course back when i was in high school but now I barely remember anything about it. I'm bored today and though I should try some python exercises.
Example:
string = '3dc8uo8c33a v8c08oizl6ga'
The code needs to remove 3d 8u 8c ... ect
so that the
answer = 'coca cola'
Assuming the rule is "split the string along whitespace, then take every third letter of the words, and add them back together", you can use
>>> string = '3dc8uo8cc33a v8c08oizl6ga'
>>> " ".join("".join(s[2::3]) for s in string.split())
'coca cola'