gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
输入月份和订购机票的数量,计算机票优惠率并输出。要求:必须用到switch语句。 月份m {7,8,9} {1~5,10,11} {6,12} 数量n n>=20 n<20…
- User
输入月份和订购机票的数量,计算机票优惠率并输出。要求:必须用到switch语句。
月份m {7,8,9} {1~5,10,11} {6,12} 数量n n>=20 n<20 n>=20 n<20 优惠率r% 15 5 30 20 10 输入格式: 月份和机票数量均为整型。
输出格式: 表格中的优惠率,整型。
- Assistant
month = int(input("请输入月份:")) num = int(input("请输入机票数量:")) rate = 0 if (month == 7 or month == 8 or month == 9) and num >= 20: rate = 15 elif (month == 7 or month == 8 or month == 9) and num < 20: rate = 5 elif (month == 1 or month == 2 or month == 3 or month == 4 or month == 5 or month == 10 or month == 11) and num >= 20: rate = 30 elif (month == 1 or month == 2 or month == 3 or month == 4 or month == 5 or month == 10 or month == 11) and num < 20: rate = 20 elif (month == 6 or month == 12) and num >= 20: rate = 10 print("优惠率为:" + str(rate) + "%") - User
用c语言写以下程序
- Assistant
#include <stdio.h> int main() { int month, num; int rate = 0; printf("请输入月份:"); scanf("%d", &month); printf("请输入机票数量:"); scanf("%d", &num); switch (month) { case 7: case 8: case 9: if (num >= 20) { rate = 15; } else { rate = 5; } break; case 1: case 2: case 3: case 4: case 5: case 10: case 11: if (num >= 20) { rate = 30; } else { rate = 20; } break; case 6: case 12: if (num >= 20) { rate = 10; } break; default: printf("无效的月份\n"); return 0; } printf("优惠率为:%d%%\n", rate); return 0; } - User
用c语言写以下程序输入月份和订购机票的数量,计算机票优惠率并输出。要求:必须用到switch语句。
月份m {7,8,9} {1~5,10,11} {6,12} 数量n n>=20 n<20 n>=20 n<20 优惠率r% 15 5 30 20 10 输入格式: 月份和机票数量均为整型。
输出格式: 表格中的优惠率,整型。
- Assistant
#include <stdio.h> int main() { int month, num; int rate = 0; printf("请输入月份:"); scanf("%d", &month); printf("请输入机票数量:"); scanf("%d", &num); switch (month) { case 7: case 8: case 9: switch (num >= 20) { case 1: rate = 15; break; case 0: rate = 5; break; } break; case 1: case 2: case 3: case 4: case 5: case 10: case 11: switch (num >= 20) { case 1: rate = 30; break; case 0: rate = 20; break; } break; case 6: case 12: switch (num >= 20) { case 1: rate = 10; break; } break; default: printf("无效的月份\n"); return 0; } printf("优惠率为:%d%%\n", rate); return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.