重複の可能性:
Python で文字列を分割し、途中でごちゃまぜにする
私は本当に行き詰まっているPythonのプログラムを持っています.パラメータですが、関数にアクセスしたり、関数を使用したりする方法がまったくわかりません...
import random
user_words = input("Enter a word or sentence: ") #Gets user input
word = list(user_words.split()) #Creating a word list of the user input
def Jumble_One_Word(x):
if len(user_words) > 2: #Only need to change words longer than 2
first_letter = user_words[0] #Takes the first letter out and defines it
last_letter = user_words[-1] #Takes the last letter out and defines it
letters = list(user_words[1:-1]) #Takes the rest and puts them into a list
random.shuffle(letters) #shuffles the list above
middle_letters = "".join(letters) #Joins the shuffled list
final_word = "".join([first_letter, middle_letters, last_letter]) #Puts final word all back in place as a list
print(final_word)#Prints out the final word all back together again
Jumbler_Count = -1
for i in range(len(word)):
Jumbler_Count + 1
Word1 = Jumble_One_Word(word[Jumbler_Count])
入力例: HELLO MY NAME IS EXPECTED OUTPUT: HLELO MY NMAE IS RESULTED OUTPUT: H leai El moymns Hoi ynmeEa lm ls Hiyn l oelEamms H naellmEyo m is