eval

温度转换

ぐ巨炮叔叔 提交于 2019-12-23 05:55:05
要求: 温度的刻画有两个不同体系:摄氏度(Celsius)和华氏度(Fabrenheit)。 请编写程序将用户输入华氏度转换为摄氏度,或将输入的摄氏度转换为华氏度。 转换算法如下:(C表示摄氏度、F表示华氏度) C = ( F - 32 ) / 1.8 F = C * 1.8 + 32 要求如下: (1) 输入输出的摄氏度采用大写字母C开头,温度可以是整数或小数,如:C12.34指摄氏度12.34度; (2) 输入输出的华氏度采用大写字母F开头,温度可以是整数或小数,如:F87.65指摄氏度87.65度; (3) 不考虑异常输入的问题,输出保留小数点后两位; (4) 使用input()获得测试用例输入时,不要增加提示字符串。 代码: 1 x=input() 2 if x[0] in ['c','C']: 3 F = eval(x[1::]) * 1.8 + 32 4 print("F{:.2f}".format(F)) 5 elif x[0] in ['f','F']: 6 C = (eval(x[1::])-32)/1.8 7 print("C{:.2f}".format(C)) 8 else: print("wrong input") 分析: 感觉这个代码的知识点还是有的。 (1)输入函数,也就是相当于C语言的scanf(),括号里面的东西会打印在屏幕上,会要求你输入一个数;

Python实现制度转换(货币,温度,长度)

邮差的信 提交于 2019-12-23 05:54:13
人民币和美元是世界上通用的两种货币之一,写一个程序进行货币间币值转换,其中: 人民币和美元间汇率固定为:1美元 = 6.78人民币。 程序可以接受人民币或美元输入,转换为美元或人民币输出。人民币采用RMB表示,美元USD表示,符号和数值之间没有空格 示例1:RMB123 示例2:USD20 TempStr = input() if TempStr[0:3] in ['RMB']: C = eval(TempStr[3:])/6.78 print("USD{:.2f}".format(C)) elif TempStr[0:3] in['USD']: F = 6.78*eval(TempStr[3:]) print("RMB{:.2f}".format(F)) 温度的刻画有两个不同体系:摄氏度(Celsius)和华氏度(Fabrenheit)。 请编写程序将用户输入华氏度转换为摄氏度,或将输入的摄氏度转换为华氏度。 转换算法如下:(C表示摄氏度、F表示华氏度) C = ( F - 32 ) / 1.8 F = C * 1.8 + 32 要求如下: (1) 输入输出的摄氏度采用大写字母C开头,温度可以是整数或小数,如:C12.34指摄氏度12.34度; (2) 输入输出的华氏度采用大写字母F开头,温度可以是整数或小数,如:F87.65指摄氏度87.65度; 示例1:C12.34 示例2

How to make runuser correctly forward all command line arguments, instead of trying to interpret them?

浪子不回头ぞ 提交于 2019-12-23 05:43:14
问题 I got this simple script: #!/bin/bash SOURCE_USER=$USER DESTINE_USER=$1 id -u $SOURCE_USER > /dev/null 2>&1 if [ "$?" == "1" ] || [ -z $SOURCE_USER ] then printf "Error: Invalid source user '$SOURCE_USER'\\n" exit 1 fi if [ -z $DESTINE_USER ] then printf "Error: Invalid destine user '$DESTINE_USER'\\n" exit 1 fi SOURCE_GROUPS=$(id -Gn ${SOURCE_USER} | sed "s/${SOURCE_USER} //g" | sed "s/ ${SOURCE_USER}//g" | sed "s/ /,/g") SOURCE_SHELL=$(awk -F : -v name=${SOURCE_USER} '(name == $1) { print

Safe way to let users register handelbars helpers in nodejs

一个人想着一个人 提交于 2019-12-23 05:05:52
问题 I have a node js web app that is using handlebars. Users are asking me to let them register their own handlebars helpers. I'm quite hesitant about letting them do it... but I'll give it a go if there is a secure way of doing it so. var Handlebars = require("handlebars"); var fs = require("fs"); var content = fs.readFileSync("template.html", "utf8"); //This helper will be posted by the user var userHandlebarsHelpers = "Handlebars.registerHelper('foo', function(value) { return 'Foo' + value; })

Synchronous <script> statements?

♀尐吖头ヾ 提交于 2019-12-23 04:43:28
问题 I am using xmlhttprequest (and eval ) to dynamically load scripts. Next I evaluate the script and look to see if there are any other scripts to load. Along the way if any of the scripts cause and exception, the error message reported indicates the line number associated with eval , not with the actual error in the script. On another question it was suggested I use <script> instead to get better error messages. Unfortunately, <script> is asynchronous, and I won't be able to control the order

Fail to create variable using eval in Node.js ES6

时光总嘲笑我的痴心妄想 提交于 2019-12-23 04:39:11
问题 It seems not possible to create a variable using eval in Node.js ES6 but I can't understand why. This happens to me on CentOS 7, but I don't believe OS is the problem here. Regular Node.js file (test.js): eval("var a=1"); console.log(a); Make the same file with .mjs extension to run with Node.js ES6 (test.mjs): eval("var a=1"); console.log(a); After that, run the 2 files with Node.js, and Node.js ES6: $ node test.js 1 $ node --experimental-modules test.mjs (node:9966) ExperimentalWarning: The

How can I get this eval() call to work in IE?

拈花ヽ惹草 提交于 2019-12-23 03:21:43
问题 I have some javascript that goes out and fetches a javascript "class" on another xhtml page. The remote javascript looks something like the following: (function() { this.init = function() { jQuery("#__BALLOONS__tabs").tabs(); }; }) After this is fetched into this.javascript, I try to eval it and instantiate: this.javascript = eval("(" + this.javascript + ")"); this.javascript = new this.javascript(); this.javascript.init(); Of course, this works perfectly in all browsers except IE. In IE, it

In node.js, How do you check whether a given string of code is syntactically correct in the most lightweight way?

风格不统一 提交于 2019-12-23 03:15:03
问题 Imagine that I accept a piece of code from a user and want to just check whether the given string is a valid JS or not? Just from the syntax perspective. function checkCode(x){ // Logic } // returns a boolean, whether 'x' is syntactically right or wrong. I don't want solutions with eval , since the whole nodejs process gets in to a syntax error when the given code, 'x' is syntactically wrong. 回答1: Don't use eval that is literally the same as handing over the control of your server to the

Bash Expression Evaluation Order on Command Line

蹲街弑〆低调 提交于 2019-12-23 03:03:50
问题 Background: I'm working on quickly calling bash command line expressions inside of SGE's job submission program qSub in parallel. While doing so, I was attempting to submit an expression (as an argument) to be ran inside of another script like so: ./runArguments.sh grep foo bar.txt > output.txt runArguments.sh looks like this: #!/bin/bash ${1} ${2} ${3} etc....to 12 The idea is that I want "grep foo bar.txt > output.txt" to be evaluated in the script...NOT ON THE COMMAND LINE. In the example

How does the eval() function change the dict?

别来无恙 提交于 2019-12-23 02:44:15
问题 How does eval() change the dict? This is an example: create a dict -> print -> eval -> print >>> a={'a':'a','b':'b'} >>> print(a) {'a': 'a', 'b': 'b'} >>> eval('a == "a"',a) True >>> print(a) {'a': 'a', '__builtins__': {'bytearray': <class 'bytearray'>, 'IndexError': <class 'IndexError'>, 'all': <built-in function all>, 'help': Type help() for interactive help, or help(object) for help about object., 'vars': <built-in function vars>, 'SyntaxError': <class 'SyntaxError'>, 'UnicodeDecodeError':