Try implementing Yubaba in Python 3

Introduction

Original author: Implementing Yubaba in Java --Qiita

-Try to implement Yubaba with JavaScript --Qiita -Try to implement Yubaba with a batch file --Qiita -Implementing Android version Yubaba with monaca (JS) --Qiita -Try to implement Yubaba with Discord Bot --Qiita

** I want to call it Hello World! Of Reiwa. ** **

I'll ride this big wave! I can't deny the suspicion of the nth decoction. .. .. </ s>

code

I'm using f-string, so please use Python 3.6 or later.

yubaba.py


import sys
import random

print("It's a contract. Write your name there.")
name = sys.stdin.readline().rstrip()
print(f"Hung.{name}I mean. It's a luxurious name.")

newName = random.choice(name)

print(f"From now on your name is{newName}It is. Mind you,{newName}That's right. I'll reply when I understand{newName}!!")

Execution example

$ python3 yubaba.py
It's a contract. Write your name there.
Yamada Taro
Hung. Is it Taro Yamada? It's a luxurious name.
From now on your name is mountain. It ’s a mountain. I'll reply when I understand, mountain!!

Crash Yubaba

As it is now, if the name is blank, it will drop. Original respect </ s>

$ python3 yubaba.py
It's a contract. Write your name there.

Hung. I mean. It's a luxurious name.
Traceback (most recent call last):
  File "yubaba.py", line 8, in <module>
    newName = random.choice(name)
  File "/usr/lib/python3.6/random.py", line 260, in choice
    raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence

Future outlook

Why don't you try making a Twitter Bot or something? (It seems more troublesome to prepare an account than writing code)

Recommended Posts