没有输入时,红宝石显示#{}(ruby show #{} when nothing is entered)

编程入门 行业动态 更新时间:2024-10-09 09:14:17
没有输入时,红宝石显示#{}(ruby show #{} when nothing is entered) print"Do you want to calculate your invoice? Please enter Yes(Y) or No(N)... " calculate_cont = "" while calculate_cont = gets.chomp() calculate_cont.to_s calculate_cont.upcase! case calculate_cont when "Y", "YES" <calculations> print "Do you wish to continue? " when "N", "NO" puts "Thank you! Press Enter to exit!" gets() exit() else puts "Error: #{calculate_cont} is not a valid entry! puts "Please Enter a valid response! Yes(Y) or No(N)" print "Do you wish to continue? " end end

当用户输入除YES或NO以外的任何其他内容时,它将使用#{calculate_cont}显示他输入的文本。 如果用户只是使用#{calculate_cont}按Enter键,我如何告诉用户他输入“Nothing”? 能做到吗?

谢谢

print"Do you want to calculate your invoice? Please enter Yes(Y) or No(N)... " calculate_cont = "" while calculate_cont = gets.chomp() calculate_cont.to_s calculate_cont.upcase! case calculate_cont when "Y", "YES" <calculations> print "Do you wish to continue? " when "N", "NO" puts "Thank you! Press Enter to exit!" gets() exit() else puts "Error: #{calculate_cont} is not a valid entry! puts "Please Enter a valid response! Yes(Y) or No(N)" print "Do you wish to continue? " end end

when the user enter anything else other than YES or NO it will show the text that he input using #{calculate_cont}. How can i tell the user that he enters "Nothing" if the user just hit enter using #{calculate_cont}? can it be done?

Thanks

最满意答案

是的,如果您正在调用gets.chomp且用户未输入任何值,则输出将为空字符串。 只是换个条件

DO SOMETHING if calculate_cont.empty?

Yes, if you are calling gets.chomp and the user entered no value, the output will be an empty string. Just put another conditional

DO SOMETHING if calculate_cont.empty?

更多推荐

本文发布于:2023-07-30 15:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338778.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:红宝石   ruby   entered   show

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!