用python编程产生一个[50,62]的随机整数x,并输出该整数x对应的英文单词。
时间: 2024-05-04 17:15:39 浏览: 99
Sure! Here's the Python code to generate a random integer between 50 and 62, and print the corresponding English word:
```python
import random
# Generate random integer between 50 and 62 (both inclusive)
x = random.randint(50, 62)
# Define a list of English words from 0 to 19 and multiples of 10 up to 90
words = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
# Print the corresponding English word for x
if x <= 20:
print(words[x])
else:
tens_digit = x // 10
ones_digit = x % 10
if ones_digit == 0:
print(words[tens_digit + 18])
else:
print(words[tens_digit + 18] + '-' + words[ones_digit])
```
For example, if the randomly generated integer is 57, the output will be "fifty-seven".