Write a function that asks for a temperature in °F degrees Fahrenheit Compute the equivalent temperature in degrees Celsius Show the converted temperature in degrees Celsius The function should keep running until no number is provided to convert You may want to use these functions:
时间: 2024-02-15 21:05:19 浏览: 24
下面是一个Matlab程序,实现了根据输入的华氏度数计算摄氏度数的功能,程序会一直运行直到没有输入为止。
```
function convertFtoC()
while true
f = input('Please enter temperature in degrees Fahrenheit (or press enter to quit): ');
if isempty(f)
break;
end
c = (f - 32) * 5/9;
fprintf('%.2f degrees Fahrenheit is equivalent to %.2f degrees Celsius.\n', f, c);
end
fprintf('Program stopped.\n');
end
```
程序通过 `input` 函数获取华氏度数 `f`,然后使用公式 `(f - 32) * 5/9` 计算出摄氏度数 `c`。使用 `fprintf` 函数输出计算结果。当用户输入空字符串时,程序退出循环,输出提示信息。
相关问题
Write a program that asks a string to the user, and counts the number of time each character occurs in the string,output is a set
Sure, I can help you with that! Here's a Python program that does what you're asking for:
```
string = input("Please enter a string: ")
count = {}
for char in string:
if char in count:
count[char] += 1
else:
count[char] = 1
print("Character count:")
for char, num in count.items():
print(char, num)
```
This program prompts the user to enter a string, then creates a dictionary called `count` to keep track of how many times each character appears in the string. It loops through each character in the string, and if the character is already in the `count` dictionary, it increments the count by 1. If the character is not yet in the dictionary, it adds it with a count of 1. Finally, it prints out the character count for each character in the string.
Write a program that asks the user for a two-digit number, then prints the English word for the number:
Sure, here's a possible solution in Python:
```
num = input("Please enter a two-digit number: ")
words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
if len(num) != 2:
print("Invalid input. Please enter a two-digit number.")
else:
if num[0] == "1":
print(words[int(num)])
else:
print(tens[int(num[0])] + "-" + words[int(num[1])])
```
This program first prompts the user to enter a two-digit number. It then checks if the input is valid (i.e., has exactly two digits). If the input is valid, it converts the number to its English word representation. For example, if the user enters "42", the program outputs "forty-two". If the user enters "13", the program outputs "thirteen".