NameError:name 'zhang' is not defined

本文分享了Python初学者在处理输入时常见的错误,详细解释了正确的输入格式和字符串使用方法,对比了不同print语句格式及其在不同环境下可能产生的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一次尝试python输入,因为输入格式问题耽误好久…
最终正确代码:

name=input('input:')
print 'hi,'+name

输入格式

如果输入字符或字符串,需要用引号表示
如:

‘zhang’
"zhang"

直接输入 zhang 的形式,就会出现题目中的报错。

输出形式

输出语句格式有如下两种:

print('hi,',name)
print 'hi,'+name

对应输出结果如下:

1->(‘hi,’,‘zhang’) #在vim中编辑后,用python命令执行.py文件时
hi, zhang #在terminal中直接执行时
2->hi,zhang #用.py文件执行时

明显第二种格式更为规整,但这种print格式在terminal下会报错,第一种不会,并不知道为什么。

64: Unicode character 张 (U+5F20) not set up for use with LaTeX. \oauthor{\bsnm{张虎成}} 64: Unicode character 虎 (U+864E) not set up for use with LaTeX. \oauthor{\bsnm{张虎成}} 64: Unicode character 成 (U+6210) not set up for use with LaTeX. \oauthor{\bsnm{张虎成}} 65: Unicode character 李 (U+674E) not set up for use with LaTeX. \oauthor{\bsnm{李雷孝}} 65: Unicode character 雷 (U+96F7) not set up for use with LaTeX. \oauthor{\bsnm{李雷孝}} 65: Unicode character 孝 (U+5B5D) not set up for use with LaTeX. \oauthor{\bsnm{李雷孝}} 66: Unicode character 刘 (U+5218) not set up for use with LaTeX. \oauthor{\bsnm{刘东江}} 66: Unicode character 东 (U+4E1C) not set up for use with LaTeX. \oauthor{\bsnm{刘东江}} 66: Unicode character 江 (U+6C5F) not set up for use with LaTeX. \oauthor{\bsnm{刘东江}} 67: Unicode character 多 (U+591A) not set up for use with LaTeX. 多 67: Unicode character 模 (U+6A21) not set up for use with LaTeX. 多模 67: Unicode character 态 (U+6001) not set up for use with LaTeX. 多模态 67: Unicode character 数 (U+6570) not set up for use with LaTeX. 多模态数 67: Unicode character 据 (U+636E) not set up for use with LaTeX. 多模态数据 67: Unicode character 融 (U+878D) not set up for use with LaTeX. 多模态数据融 67: Unicode character 合 (U+5408) not set up for use with LaTeX. 多模态数据融合 67: Unicode character 研 (U+7814) not set up for use with LaTeX. 多模态数据融合研 67: Unicode character 究 (U+7A76) not set up for use with LaTeX. 多模态数据融合研究 67: Unicode character 综 (U+7EFC) not set up for use with LaTeX. 多模态数据融合研究综 67: Unicode character 述 (U+8FF0) not set up for use with LaTeX. 多模态数据融合研究综述 : example' multiply defined. : example' multiply defined. 143: Font shape `U/rsfs/m/n' in size <8.43146> not available(Font) size <8> substituted 143: Font shape `U/rsfs/m/n' in size <5.52061> not available(Font) size <6> substituted : Underfull \vbox (badness 10000) has occurred while \output is active [] : Underfull \vbox (badness 10000) has occurred while \output is active [] : destination with the same identifier (name{figure.1}) has been already used, duplicate ignored<argument> ...shipout:D \box_use:N \l_shipout_box \__shipout_drop_firstpage_... : destination with the same identifier (name{figure.2}) has been already used, duplicate ignored<argument> ...shipout:D \box_use:N \l_shipout_box \__shipout_drop_firstpage_... : multiple pdfs with page group included in a single page>]<fazhan (1).pdf, id=125, page=2, 963.6pt x 542.025pt>File: fazhan (1).pdf Graphic file (type pdf)<use fazhan (1).pdf, page 2> 176: Citation `pearson1901liii' on page 3 undefined 176: Citation `blei2003latent' on page 3 undefined 176: Citation `thompson2000canonical' on page 3 undefined 176: Citation `hinton2006reducing' on page 3 undefined 176: Citation `graves2012long' on page 3 undefined 176: Citation `vaswani2017attention' on page 3 undefined 176: Citation `krizhevsky2012imagenet' on page 3 undefined : Underfull \vbox (badness 10000) has occurred while \output is active [] : destination with the same identifier (name{figure.3}) has been already used, duplicate ignored<argument> ...shipout:D \box_use:N \l_shipout_box \__shipout_drop_firstpage_... : Underfull \vbox (badness 10000) has occurred while \output is active [] 227: Font shape `U/rsfs/m/n' in size <4.015> not available(Font) size <5> substituted : Underfull \vbox (badness 10000) has occurred while \output is active [] : destination with the same identifier (name{table.1}) has been already used, duplicate ignored<argument> ...shipout:D \box_use:N \l_shipout_box \__shipout_drop_firstpage_... : No positions in optional float specifier. : Underfull \vbox (badness 10000) has occurred while \output is active [] : destination with the same identifier (name{table.2}) has been already used, duplicate ignored<argument> ...shipout:D \box_use:N \l_shipout_box \__shipout_drop_firstpage_... : Underfull \vbox (badness 10000) has occurred while \output is active [] : destination with the same identifier (name{table.3}) has been already used, duplicate ignored<argument> ...shipout:D \box_use:N \l_shipout_box \__shipout_drop_firstpage_... : Underfull \vbox (badness 10000) has occurred while \output is active [] : destination with the same identifier (name{figure.4}) has been already used, duplicate ignored<argument> ...shipout:D \box_use:N \l_shipout_box \__shipout_drop_firstpage_... 384: Font shape `OMS/cmss/m/n' undefined(Font) using `OMS/cmsy/m/n' instead(Font) for symbol `textbraceleft' 420: Overfull \hbox (7.55843pt too wide) in paragraph : Underfull \vbox (badness 10000) has occurred while \output is active [] 451: Citation `bib1' on page 10 undefined 451: Citation `bib2' on page 10 undefined 453: Citation `bib3' on page 10 undefined 453: Citation `bib4' on page 10 undefined 453: Citation `bib5' on page 10 undefined : Underfull \vbox (badness 10000) has occurred while \output is active [] : Underfull \vbox (badness 10000) has occurred while \output is active [] 548: Underfull \hbox (badness 1859) in paragraph 548: Underfull \hbox (badness 10000) in paragraph 548: Underfull \hbox (badness 10000) in paragraph 548: Underfull \hbox (badness 4634) in paragraph 548: Underfull \hbox (badness 10000) in paragraph : Underfull \vbox (badness 10000) has occurred while \output is active [] 564: Difference (4) between bookmark levels is greater than one, level fixed 572: Difference (3) between bookmark levels is greater than one, level fixed : Underfull \vbox (badness 10000) has occurred while \output is active [] : Underfull \vbox (badness 10000) has occurred while \output is active [] : There were undefined citations. : Underfull \vbox (badness 10000) has occurred while \output is active [] : Size substitutions with differences(Font) up to 0.985pt have occurred. : Some font shapes were not available, defaults substituted. : There were multiply-defined labels.
最新发布
08-08
# -*- coding: utf-8 -*- """ @author: zhang'xin'ge """ # 导入必要的库和数据 import pandas as pd from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from keras.models import Sequential from keras.layers import LSTM, Dense data = pd.read_csv('D:/MATLAB/data_test/0713_电子版更新.csv') # 将数据集拆分为训练集和测试集,并进行特征缩放: X = data.drop(['体质类型'], axis=1).values y = data['体质类型'].values X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) scaler = StandardScaler() X_train_scaled = scaler.fit_transform(X_train) X_test_scaled = scaler.transform(X_test) #使用LSTM算法训练一个分类模型 model = Sequential() model.add(LSTM(64, input_shape=(X_train_scaled.shape[1], 1))) model.add(Dense(32, activation='relu')) model.add(Dense(9, activation='softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) # 将训练集和测试集转换为LSTM模型需要的输入格式: X_train_lstm = X_train_scaled.reshape((X_train_scaled.shape[0], X_train_scaled.shape[1], 1)) X_test_lstm = X_test_scaled.reshape((X_test_scaled.shape[0], X_test_scaled.shape[1], 1)) # 使用训练集对模型进行训练: model.fit(X_train_lstm, y_train, epochs=50, batch_size=32, validation_data=(X_test_lstm, y_test)) # 使用训练好的模型对测试集进行预测,并计算准确率: y_pred = model.predict_classes(X_test_lstm) accuracy = (y_pred == y_test).mean() print('Accuracy:', accuracy) 出现以下报错,如何解决 File "D:\Anaconda\lib\site-packages\typing_extensions.py", line 137, in _collect_type_vars 'TypedDict', NameError: name '_should_collect_from_parameters' is not defined
07-22
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值