我刚刚开始学习python的基础知识。我正在尝试让输出说"'User‘现在是'25’岁。‘User’将在'Year‘中活到100岁“。
在我的提取中,我无法获得‘年份’在output.Below是我的代码.Please建议!
from datetime import datetime
from datetime import timedelta
name=input("Enter you name : ")
age=input("Enter your age : " )
years_left=(100-int(age))
date
如果用户没有输入True或False,我想继续询问用户是否需要isMale。但是,即使我进入True或False,while循环也会继续询问。我也不知道原因。 name = input("Name: ")
age = int(input("Age: "))
isMale = bool(input("Male? "))
while (isMale != True) or (isMale != False): #Is this correct?
print("Wrong Input. Please type True/False&
代码
character_name = "Tom"
character_age = "50"
is_male = False
print("There once was a man named " + character_name + ", ").
print("he was " + character_age + " years old. ")
character_name
我正在学习C#,并偶然发现了一小部分代码:
{
class Program
{
static void Main(string[] args)
{
int age = 20;// declaring variable and assign 20 to it.
Console.WriteLine("You are {0} years old.",age);
Console.ReadLine();
}
}
}
我不明白{0}将如何输出20,我的意思是它不像数
我有如下数据:
df:
Name Age Type Result
Ra 35 adult $name is an $type of $age years
Ro 12 child $name behaves like $type as he is $age years old
<+100 rows>
结果列中的每个语句都是不同的。我所需要做的就是用适当的值填充变量。
我知道有多个选项,如格式化字符串和string format方法,但无法理解如何在dataframe场景中实现
我是一个新的Python,并尝试使用KeyError ()函数:
def hello( name="Sean", age=0 ):
return 'Hello, ' + name + " you are { age } years old".format( age )
sentence1 = hello( 'Mark', 17 )
错误:
KeyError: ' age '
我做错了什么?
我正在尝试使用这些代码行
class Student {
var name: String
var age: Int?
init(name: String) {
self.name = name
}
func description() -> String {
return age != nil ? "\(name) is \(age) years old." : "\(name) hides his age."
}
}
var me = Student(name:
我需要一个函数,用正确的变量替换'{}‘中的每个variable_name。如下所示:
$data["name"] = "Johnny";
$data["age"] = "20";
$string = "Hello my name is {name} and I'm {age} years old.";
$output = replace($string, $data);
echo $output;
//outputs: Hello my name is Johnny and I'm
我正在写一段代码,它询问用户的名字,然后是第二个名字,然后是他们的年龄,但随后我将其打印出来,但我不确定如何给出答案。
print ("What is your first name?"),
firstName = input()
print ("What is you last name?"),
secondName = input()
print ("How old are you?")
age = input()
print ("So, you're %r %r and you're %r years old.
假设我有一个文本模板,其中包含许多需要填充的字段:
var template = "hello {$name}. you are {$age} years old. you live in {$location}"
和要替换的值的IDictionary<string,string>:
key | value
===================
name | spender
age | 38
location| UK
填充模板的简单方法可能如下所示:
var output = template;
foreach(var kvp in temp
我刚刚了解到Python中没有整数的引号,但为什么在这种情况下需要它:
character_name = "Tom"
age = "50"
print("There once was a man named " + character_name + ",")
print("he was " + age + " years old.")
我有点困惑。之前我发布了一个问题:
它得到的答案是使用String.format() with format specifiers (%s, %d, %f...)。
虽然答案有点混乱,但我知道%f意味着转换(?)
但是如何使用这种方法打印出age和name。我的尝试:
// DISPLAY Person name and age
public String displayProfile() {
return String.format(%fgetAge(), %fgetName())
}
执行上述方法的主要方法:
if (optionSelected == 2)
我有一个字符串var str1 = "My name is {{0}}, I am {{1}} years old.",我想使用String.Format(str1, 'Pavel', 29);
当然,它不起作用,因为String.Format()希望参数占位符位于一个花括号中。
所以,我必须这样修改我的字符串:
for (int i = 0; i < 10; i++)
{
str1 = str1.Replace("{{" + i + "}}", "{" + i + "}");
}
我
这就是我所知道的
str = String.Format("Her name is {0} and she's {1} years old", "Lisa", "10");
但我想要的是
str = String("Her name is @name and she's @age years old");
str.addParameter(@name, "Lisa");
str.addParameter(@age, 10);
output = output.replaceAll("%(\\w+)%",getVar("$1"));
public String getVar(name){...return formatted;}
我有这行代码(在JAVA中),还有一个名为getVar()的函数,它将给出我们想要的变量的值。这个函数工作得很好,但是这段代码似乎不再寻找组了。
我用这个正则表达式格式化的字符串是:
"My name is %name% and I am %age% years old."
而不是还给我:"My name is Paulo and I